puppy Posted April 29, 2008 Share Posted April 29, 2008 I have an SQL query on my page that gets a list of people from the DB. I am trying to have it so that when you click on the date it submits a form (post) with the ID number of that row to another page. I have the <form> function in the echo of my query, here is what it is. $result = mysql_query("SELECT * FROM criminals WHERE $field LIKE '%$search%' ORDER BY date"); while($row=mysql_fetch_array($result)) { $user=$row["user"]; $date=$row["date"]; $crime=$row["crime"]; $officer=$row["officer"]; $dispatch=$row["dispatch"]; $type=$row["type"]; $comment=$row["comment"]; $loc=$row["loc"]; $id=$row["id"]; echo "<tr> <td align='center' class='row1h' ><p class='forumdesc style2'><strong><form method='POST' action='ticket.php' id='$id'> <input type='hidden' name='Country' value='$id'> <a href='javascript:void(0);' onclick='document.forms['$id'].sumbit();'>$date</a></form></strong></p></td> <td class='row1h' align='left'><p class='forumdesc style2'><strong>$user</strong></p></td> <td class='row1h' align='left'><p class='forumdesc style2'><strong>$crime</strong></p></td> <td class='row1h' align='left' nowrap='nowrap'><p class='forumdesc style2'><strong>$officer</strong></p></td> </tr>"; } I get a link on the date like I am supposed to but I end up getting a javascript error, here is what the echo outputs. <td align='center' class='row1h' ><p class='forumdesc style2'><strong><form method='POST' action='ticket.php' id='1'> <input type='hidden' name='id' value='1'> <a href='javascript:void(0);' onclick='document.forms['1'].sumbit();'>4/29/2008</a></form></strong></p></td> <td class='row1h' align='left'><p class='forumdesc style2'><strong>Fuzz_monkey</strong></p></td> <td class='row1h' align='left'><p class='forumdesc style2'><strong>Bad behavior on the sidewalk</strong></p></td> <td class='row1h' align='left' nowrap='nowrap'><p class='forumdesc style2'><strong>pUPPy (702)</strong></p></td> </tr> </tbody> </table> When I use firefox to look at the source it highlights this section for the error in red : onclick='document.forms['1'].sumbit();'>4/29/2008</a> Any ideas? Link to comment https://forums.phpfreaks.com/topic/103491-php-sql-javascript-in-form-submit-not-working/ Share on other sites More sharing options...
xenophobia Posted May 6, 2008 Share Posted May 6, 2008 You got few error: - Javascript form are counting from 0. - You should't enclose your number with quotes. - Your onclick should use double-quotes. (\"document.forms['1'].sumbit();\") My best suggestion is: document.getElementById('$i').submit(); since you already assign an id to your form. Link to comment https://forums.phpfreaks.com/topic/103491-php-sql-javascript-in-form-submit-not-working/#findComment-534210 Share on other sites More sharing options...
nogray Posted May 6, 2008 Share Posted May 6, 2008 form name or id can't start with a number, change it to id='frm_".$id."' Link to comment https://forums.phpfreaks.com/topic/103491-php-sql-javascript-in-form-submit-not-working/#findComment-534453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.