claro Posted September 23, 2011 Share Posted September 23, 2011 greetings! I have here codes that have two checkboxes, if 1 checkbox is checked, the other and textbox is disabled. I think my codes in js is functional, my problem is how to put it inside the mysql_fetch_array, I want to put those checkbox in every data fetch from my db. only the first data is affected ..i really appreciate your help guys! <?php include('connect-db.php');?> <html> <head> <script language = "Javascript" type="text/javascript" > function checkbox_disabled(tocheck,todisable,todisable2) { var x = document.getElementById(tocheck); if(x.checked){ document.getElementById(todisable).disabled=true; document.getElementById(todisable2).disabled=true; document.getElementById(todisable2).checked = false; }else{ document.getElementById(todisable).disabled=false; document.getElementById(todisable2).disabled=false; document.getElementById(todisable2).checked = true; } } </script> </head> <body> <?php echo "<table>"; $query = mysql_query("SELECT * FROM tbl_user") or die (mysql_error()); while ($row = mysql_fetch_array($query)) { echo '<tr>'; echo '<td>'.$row['user_Id'].'</td>'; echo '<td>'. $row['user_Fname'].'</td>'; echo '<td>'.$row['user_Lname'].'</td>'; echo "<td><input type='checkbox' id='checkbox1' value ='checked' onclick=checkbox_disabled('checkbox1','textbox1','checkbox2')></td>"; echo '<td><input type="checkbox" id = "checkbox2"><input type="text" id="textbox1" /><td>'; echo '</tr>'; } echo "</table>"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/247744-how-to-loop-javascript-inside-the-mysql_fetch_array/ Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 I'm really not sure what you mean, but it sounds like you just need to escape your quotes properly and add a little incremental variable to keep changing the checkbox names... Try this: (untested) <?php $i = 1; while ($row = mysql_fetch_array($query)){ echo "<tr>"; echo "<td>".$row['user_Id']."</td>"; echo "<td>". $row['user_Fname']."</td>"; echo "<td>".$row['user_Lname']."</td>"; echo "<td><input type='checkbox' id='checkbox".$i."' value ='checked' onclick='checkbox_disabled(\'checkbox".$i."\',\'textbox".$i."\',\'checkbox".$i."2\');'></td>"; echo "<td><input type='checkbox' id='checkbox".$i."2'><input type='text' id='textbox".$i."' /><td>"; echo "</tr>"; $i++ } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247744-how-to-loop-javascript-inside-the-mysql_fetch_array/#findComment-1272220 Share on other sites More sharing options...
claro Posted September 24, 2011 Author Share Posted September 24, 2011 thank you for your help!! but i still it does'nt work. attached is my expected output. It did work to my first data record, my problem is it doesnt work to other. <?php echo "<table>"; $query = mysql_query("SELECT * FROM tbl_user") or die (mysql_error()); while ($row = mysql_fetch_array($query)) { echo '<tr>'; echo '<td>'.$row['user_Id'].'</td>'; echo "<td><input type='checkbox' id='checkbox1' value ='checked' onclick=checkbox_disabled('checkbox1','textbox1','checkbox2')></td>"; echo '<td><input type="checkbox" id = "checkbox2"><input type="text" id="textbox1" /><td>'; echo '</tr>'; } echo "</table>"; ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247744-how-to-loop-javascript-inside-the-mysql_fetch_array/#findComment-1272232 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 did you use the code I gave you? (the one you're posting is not what I gave you) Quote Link to comment https://forums.phpfreaks.com/topic/247744-how-to-loop-javascript-inside-the-mysql_fetch_array/#findComment-1272234 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 try this: (changed quotes to double in javascript call. Should work now) echo "<tr>"; echo "<td>".$row['user_Id']."</td>"; echo "<td>". $row['user_Fname']."</td>"; echo "<td>".$row['user_Lname']."</td>"; echo "<td><input type='checkbox' id='checkbox".$i."' value ='checked' onclick='checkbox_disabled(\"checkbox".$i."\",\"textbox".$i."\",\"checkbox".$i."2\");'></td>"; echo "<td><input type='checkbox' id='checkbox".$i."2'><input type='text' id='textbox".$i."' /><td>"; echo "</tr>"; $i++; Quote Link to comment https://forums.phpfreaks.com/topic/247744-how-to-loop-javascript-inside-the-mysql_fetch_array/#findComment-1272235 Share on other sites More sharing options...
claro Posted September 24, 2011 Author Share Posted September 24, 2011 thank you! thank you! you're genius!!it works now. Quote Link to comment https://forums.phpfreaks.com/topic/247744-how-to-loop-javascript-inside-the-mysql_fetch_array/#findComment-1272236 Share on other sites More sharing options...
claro Posted September 24, 2011 Author Share Posted September 24, 2011 but I still don't know how it was done. I'm new in php/js. what can you say about this, my codes now are functional, i cant understand there is checkbox/texbox that doesnt work. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247744-how-to-loop-javascript-inside-the-mysql_fetch_array/#findComment-1272242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.