Jump to content

PHP, SQL - javascript in form submit not working


puppy

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.