0

jQuery script which opens selected box in new window one by one for specific time. But it runs all boxes on click button whether i check anything or not I am so Confused.

My jQuery code:

function bon()
{
    var field = document.getElementsByName('list');
    var len = field.length;     
    var j=0;
    for (i = 0; i < field.length; i++)
    {
        lk[j] = document.getElementById('addlink_'+i).value;    
        j++;    
    }
 win = window.open("","myWindow","height=500,width=500,menubar=no,status=no"); 
 process();
 var interval  =  document.getElementById('interval').value;
window.setInterval(function(){ process();}, interval);      
}
function process()
{
        if(oldval<lk.length)
        {
                 var ln =lk[oldval];
                 win.location.href =ln; 
                 //$.post("updateclick.php",{dbid:recordid},function(data) {  document.getElementById(countid).innerHTML = data; });                 
                 oldval =oldval+1;
        }
        else
        {
             window.location.href=location.href;
        }
}
function process1(a,b)
{
    if(document.getElementById('chkbox_'+a).checked==true)
    {

    }
    else
    {
        thisimg(a,b);
    }
}

And my HTML code is:

<div class='posts'>
    <input style='float:left; height:85px;' type='checkbox' name='list' value='chck_".$counter."' id='chkbox_".$counter."'/>
    <div class='title box' onclick='process1(".$counter.",".$row['id'].")'>
        <div style='float:left;' onclick='thisimg(".$counter.",".$row['idDiv1'].")'>
            <img src='".$imgpath."' height='50' width='50' />
        </div>
        <div class='click' style='float:right;'>
            <b>Clicks <br/>
                <div id='count_".$counter."'> ".$click." </div>
                <input type='hidden' id='addlink_".$counter."' value='".$app_link."' rel='nofollow'/></b>
        </div>
        <div style='float:left; width:100px; overflow:hidden; white-space: pre;'>
             <b> ".$title."</b>
            <br/>".$beforetime."
        </div>
    </div>
</div>

This is my button code:

<select id="interval">
    <option value="5000"> 5 Seconds</option>
    <option value="10000"> 10 Seconds</option>
  </select>
  <input class="butn" type="button" value="Collect" onclick="bon()" />

Working: the user has to select the check boxes which they want to open in new window one by one for specific time( provided in my option box). But whether i check any one or not it executes one by one all like it selects all check boxes.

Ok here is the actual HTML that prints

<div class=posts>
  <input style='float:left; height:85px;' type=checkbox name=list value=chck_0 id=chkbox_0 />
   <div class='title box' onclick='process1(0,190757)'>
    <div style='float:left;' onclick='thisimg(0,190757)'>
      <img src='/images/3c59e768eefb1d5d4a0bfdf0ae23cf5a.png' height=50 width=50 />
    </div>
   <div class=click style='float:right;'><b>Clicks <br/> 
    <div id=count_0> 0 
    </div>
    <input type=hidden id=addlink_0 value='/link/zqdba3' rel=nofollow></b>
   </div>
  <div style='float:left; width:100px; overflow:hidden; white-space: pre;'> <b> Title</b><br/>2 Hs 31 Ms ago
  </div>
 </div>
</div>

Please help I am very confused.

4
  • There is a problem with your HTML code, please correct it and try again.
    – totten
    Jul 21, 2012 at 22:35
  • The HTML is Corrected But Still Same Problem...
    – Asim
    Jul 21, 2012 at 23:12
  • can you explain the code further? Once you click on one of the checkbox you only want a single window to open but you get multiple windows instead? Jul 21, 2012 at 23:59
  • the user has to select the check boxes which they want to open in new window one by one for specific time( provided in my option box). But whether i check any one or not it executes one by one all like it selects all check boxes.
    – Asim
    Jul 22, 2012 at 0:10

1 Answer 1

0

You are iterating over all of your addlink_ inputs without looking at the checkbox. If the ith checkbox is checked, then push the corresponding input element's value onto the array.

var field = document.getElementsByName('list');
var len = field.length;     
lk = [];
for (i = 0; i < len; i++) {
    if(field[i].checked) {
        lk.push(document.getElementById('addlink_'+i).value);
    }
}
3
  • i have one more question i Have this click update script how can i interact this with selected check box to update click after executing each window... <script type="text/javascript"> function thisimg(id,recordid) { var newid = "addlink_"+id; var countid = "count_"+id; var url = "facebook/updateclick.php"; $.post(url,{dbid:recordid},function(data) { document.getElementById(countid).innerHTML = data; }); var url =document.getElementById(newid).value; window.open (url,"myWindow","height=500,width=500,menubar=no,status=no"); } </script>
    – Asim
    Jul 22, 2012 at 21:11
  • If you have that much code in a comment, you should probably just create a separate question.
    – Dennis
    Jul 22, 2012 at 21:22
  • please i have to post everything again the question is related to this question please..
    – Asim
    Jul 22, 2012 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.