0

I want to use the jQuery Dropdown CheckList in a while loop. But in only display the jQuery Dropdown Checklist in the first row. For the rest of the row it didn't call the jQuery Dropdown Checklist function. Is there any way for me to call the jQuery function dynamically.

//This is the java script for calling the dropdown list
    <meta http-equiv="refresh" content="600" >
        <!-- Apply dropdown check list to the selected items  -->
    <script type="text/javascript">

    $(document).ready(function(){$("#s1").dropdownchecklist( { width: 300 } );});

     </script>  
//this is the while loop which display the list of row with drop down checklist in it
         //display the list of rows



 while($rows = mysql_fetch_array($query)){

        <select id="s1" multiple="multiple" >

        <option value=""></option>
    <?php while($rowsakh= mysql_fetch_array($resultakh)) { ?>
    <option  value='<?php echo $rowsakh['diet_id']; ?>'><?php echo $rowsakh['diet_name']; ?></option> <?php } ?>
    </select>
         }//end while loop

If I try to make the id="s1" to be a dynamic variable where it increases for each loop. Is there any way to make the id="s1" dynamically or the syntax for me to do it.

1
  • what is your $query?
    – yvonnezoe
    Commented May 16, 2013 at 3:25

1 Answer 1

0

If you want the id to be dynamic like id="s1" id="s2" you can accomplish this by defining a variable to the value of 1 and the increase the variable by 1 for every time it looks so your code would be like this,

$i = 1;
while($rows = mysql_fetch_array($query)){

<select id="s<?php echo $i; ?>" multiple="multiple" >
    <option value=""></option>
    <?php while($rowsakh= mysql_fetch_array($resultakh)) { ?>
    <option  value='<?php echo $rowsakh['diet_id']; ?>'><?php echo $rowsakh['diet_name']; ?></option> <?php } ?>
</select>
$i++;
}
1
  • Thank you for your help.i was able to solve my problems.its turn out that i'm using the wrong syntax to passing the php value in the javascripts.
    – Din Dang
    Commented May 17, 2013 at 1:16

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.