Call javascript from php in while loop -



Call javascript from php in while loop -

i hope can help me, i've been struggling, have , within form table has columns. retrieves info mysql table. in column 2 displays current info , in column 3 displays form options update values, eg:

first name: john [form field update] date of birth: 1970-01-01 [form field update]

i'm struggling java script functioning popup calendar. if run html works fine when within php can't run because displays form within while loop:

<head> <script src="datetimepicker_css.js"></script> </head> <body> <?php ..... $sql2="select * em_detail id = '$data1'"; $result2=mysql_query($sql2); echo "<form action='upd_emp.php' method=post>"; while($row2 = mysql_fetch_assoc($result2)) { $id_2 = $row2['id'] ; ..... echo "<tr>"; echo "<td height=35px><strong>date of birth: </strong></td>"; echo "<td>$dob_2</td>"; echo "<td><input size=30 type=text name=dob id=demo1/></td>"; echo "<td align=left><img src=images/cal.gif onclick=javascript:newcsscal('demo1') style=cursor:pointer/></td>"; echo " </tr>";

it's not working because in every row print out in loop, corresponding inputs have same id — demo1.

ids in html should unique across elements. means every calendar opens looks input id of demo1, , finds same one.

you'll want create sure input in each row has unique id. can utilize variable have, $id_2, or can increment counter each iteration of loop , utilize that. utilize unique number in both id of <input> , onclick calendar trigger.

<?php //... $counter = 0; while($row2 = mysql_fetch_assoc($result2)) { $id_2 = $row2['id'] ; ?> <tr> <td height="35"><strong>date of birth: </strong></td> <td><?php echo $dob_2; ?></td> <td><input size="30" type="text" name="dob_<?php echo $id_2; ?>" id="demo_<?php echo $counter; ?>"/></td> <td align="left"><img src="images/cal.gif" onclick="newcsscal('demo_<?php echo $counter; ?>');" style="cursor:pointer"/></td> </tr> <?php $counter++; }

also i've update code next changes:

name of input should unique. you should utilize quotes around attribute values in html no need echo html code if doesn't have variables - utilize ?> , <?php when want php code. javascript: not needed in onclick attributes — javascript, , javascript: becomes label isn't used.

php javascript

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -