Jump to content

[SOLVED] Onclick submit form


nealios

Recommended Posts

I have a php/html page that enables me to update delete and add new jobs to my database. depending on what function i want the page to do i select the relevant radio button (update,delete,add) and hit a form submit button. It then carries out the function i want it to.

 

<input type="submit" value=" Do  it " />

 

 

I am trying to change the appearance of my form submit button by using a combination of javascript and css.

 

<a href="" onclick="record_mod.submit()" class="button" span class="icon"> Submit </span><a>

 

The button now looks how i want it to but i have lost its functionality as it doesnt seem to be working with the radio buttons anymore.

 

Below is my form code. can anyone shed on light on what im doing wrong?

 

Many thanks

 

<form name=\"record_mod\" method=\"post\" action=\"jobadmin.php\">
<table border=\"1\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>
      <table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
        <tr>
          <td align=\"left\">JobID: {$row['JobID']}</td>
        </tr>
      </table>
    
  <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
        <tr>
          <td width=\"75\" align=\"right\">Start Date:</td>
          
	  <td colspan=\"3\">
	  
	  <input id=\"demo3\" type=\"text\" name=\"StartDate\" size=\"25\" value=\"{$row['StartDate']}\">  
	  <a  href=\"javascript:NewCal('demo3','ddmmyyyy')\"><img  src=\"cal.gif\" width=\"16\"  height=\"16\" border=\"0\"></a>
	  


	  
        </tr>
        <tr>
          <td width=\"75\" align=\"right\">End Date:</td>
          <td><input id=\"demo4\" type=\"text\" name=\"EndDate\" size=\"25\" value=\"{$row['EndDate']}\">  
	  <a  href=\"javascript:NewCal('demo4','ddmmyyyy')\"><img  src=\"cal.gif\" width=\"16\"  height=\"16\" border=\"0\"></a></td></tr>
          <td>Job Address 1:</td>
	  
          <td><input name=\"JobAddress1\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress1']}\" /></td>
	   <td>Job Address 2:</td>
          <td><input name=\"JobAddress2\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress2']}\" /></td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
        <tr>
          <td width=\"75\" align=\"right\">Postcode:</td>
          <td><input name=\"JobPostcode\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['JobPostcode']}\" /></td>
        </tr>
        <tr>
          <td width=\"75\" align=\"right\">Price :</td>
          <td><input name=\"Price\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['Price']}\" /></td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
        <tr>
          <td width=\"75\" align=\"right\">Description:</td>
          <td><input name=\"Description\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Description']}\" /></td>
          <td>Materials:</td>
          <td><input name=\"Materials\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Materials']}\" /></td>
       <td>Customer Id:</td> 
   
   <td><input name=\"cid\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['cid']}\" /></td>
    <tr> <td>First Name:</td> 
	<td><input name=\"first_name\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['first_name']}\" /></td></tr><td>surname:</td> 
	   <td><input name=\"surname\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['surname']}\" /></td>
 <td>Paid<input name =\"paid\" type=\"checkbox\" value=\"{$row['paid']}\" /></td>


   
   
      </table>
     
      <hr align=\"left\" width=\"650\">
      <table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
        <tr>
          <td align=\"left\">Process</td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
        <tr>
          <td><input name=\"op\" type=\"radio\" value=\"1\" /> Update Record</td>
          <td><input name=\"op\" type=\"radio\" value=\"2\" /> New Record</td>
          <td><input name=\"op\" type=\"radio\" value=\"3\" /> DELETE Record</td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
        <tr>
          <td colspan=\"3\"><input type=\"submit\" value=\" Do It ! \" /></td>
          <td><a href=\"jobs.php\" class=\"button\" span class=\"icon\"> Records List </span></a></td>      
          <td><a href=\"jobadmin.php?JobID=0&op=4\" class=\"button\" span class=\"icon\"> Synchronize</span></a></td>
	   <td style=\"padding-left: 50px;\">
           <td> <a href=\"jobadmin.php?JobID=$JobID&op=5&move=2\" class=\"button\" span class=\"icon\">Previous</span></a></td><td>Navigate
  		   <td> <a href=\"jobadmin.php?JobID=$JobID&op=5&move=1\" class=\"button\" span class=\"icon\">Next</span></a></td>
          </td>
	  <td><a href=\"invoice.php?JobID={$row['JobID']}\" class=\"button\" span class=\"icon\"> Create Invoice </span></a></td> 
        </tr>
      </table>
    </td>
  </tr>
</table></p>
<input name=\"JobID\" type=\"hidden\" value=\"$JobID\" />
</form>"

 

 

Link to comment
https://forums.phpfreaks.com/topic/78278-solved-onclick-submit-form/
Share on other sites

Your code seems to function right; the "op" variable is still being passed to your PHP script. You can test it for yourself by changing the form method from post to get and then click the submit link. Then look at your address bar; at the string that is passed to you PHP script. There you will see that the variable and the variable's value are being passed to you script. I did change you submit href from an empty value to a anchor; so maybe that will correct the problem, because after I did that - it worked fine on my end.

 

Try This:

 

<?php

echo "<form name=\"record_mod\" method=\"post\" action=\"jobadmin.php\">
<table border=\"1\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>
      <table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
        <tr>
          <td align=\"left\">JobID: {$row['JobID']}</td>
        </tr>
      </table>
    
  <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
        <tr>
          <td width=\"75\" align=\"right\">Start Date:</td>
          
	  <td colspan=\"3\">
	  
	  <input id=\"demo3\" type=\"text\" name=\"StartDate\" size=\"25\" value=\"{$row['StartDate']}\">  
	  <a  href=\"javascript:NewCal('demo3','ddmmyyyy')\"><img  src=\"cal.gif\" width=\"16\"  height=\"16\" border=\"0\"></a>
	  


	  
        </tr>
        <tr>
          <td width=\"75\" align=\"right\">End Date:</td>
          <td><input id=\"demo4\" type=\"text\" name=\"EndDate\" size=\"25\" value=\"{$row['EndDate']}\">  
	  <a  href=\"javascript:NewCal('demo4','ddmmyyyy')\"><img  src=\"cal.gif\" width=\"16\"  height=\"16\" border=\"0\"></a></td></tr>
          <td>Job Address 1:</td>
	  
          <td><input name=\"JobAddress1\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress1']}\" /></td>
	   <td>Job Address 2:</td>
          <td><input name=\"JobAddress2\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress2']}\" /></td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
        <tr>
          <td width=\"75\" align=\"right\">Postcode:</td>
          <td><input name=\"JobPostcode\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['JobPostcode']}\" /></td>
        </tr>
        <tr>
          <td width=\"75\" align=\"right\">Price :</td>
          <td><input name=\"Price\" type=\"text\" size=\"40\" maxlength=\"25\" value=\"{$row['Price']}\" /></td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
        <tr>
          <td width=\"75\" align=\"right\">Description:</td>
          <td><input name=\"Description\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Description']}\" /></td>
          <td>Materials:</td>
          <td><input name=\"Materials\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Materials']}\" /></td>
       <td>Customer Id:</td> 
   
   <td><input name=\"cid\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['cid']}\" /></td>
    <tr> <td>First Name:</td> 
	<td><input name=\"first_name\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['first_name']}\" /></td></tr><td>surname:</td> 
	   <td><input name=\"surname\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['surname']}\" /></td>
 <td>Paid<input name =\"paid\" type=\"checkbox\" value=\"{$row['paid']}\" /></td>


   
   
      </table>
     
      <hr align=\"left\" width=\"650\">
      <table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
        <tr>
          <td align=\"left\">Process</td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
        <tr>
          <td><input name=\"op\" type=\"radio\" value=\"1\" /> Update Record</td>
          <td><input name=\"op\" type=\"radio\" value=\"2\" /> New Record</td>
          <td><input name=\"op\" type=\"radio\" value=\"3\" /> DELETE Record</td>
        </tr>
      </table>
      <table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
        <tr>
          <td colspan=\"3\"><a href=\"#\" onclick=\"record_mod.submit()\" class=\"button\" span class=\"icon\"> Submit </span><a></td>
          <td><a href=\"jobs.php\" class=\"button\" span class=\"icon\"> Records List </span></a></td>      
          <td><a href=\"jobadmin.php?JobID=0&op=4\" class=\"button\" span class=\"icon\"> Synchronize</span></a></td>
	   <td style=\"padding-left: 50px;\">
           <td> <a href=\"jobadmin.php?JobID=$JobID&op=5&move=2\" class=\"button\" span class=\"icon\">Previous</span></a></td><td>Navigate
  		   <td> <a href=\"jobadmin.php?JobID=$JobID&op=5&move=1\" class=\"button\" span class=\"icon\">Next</span></a></td>
          </td>
	  <td><a href=\"invoice.php?JobID={$row['JobID']}\" class=\"button\" span class=\"icon\"> Create Invoice </span></a></td> 
        </tr>
      </table>
    </td>
  </tr>
</table></p>
<input name=\"JobID\" type=\"hidden\" value=\"$JobID\" />
</form>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.