PHP submit form and update variable onclick

Trying to create a form where the user searches for a name.  The first step is to select whether they want to search for a common name or a scientific name.  The next step is to select the first letter of that name (A, B, C, etc.).  When they click on the letter (i.e. A), I need the hyperlink to update a hidden field with the letter they clicked on and then pass the form (which passes the choice of common name or scientific name and the letter) to the next page.

My code below does not update the letter they chose.  Please advise
<form id="form1" name="form1" method="post" action="grass1.php">
  <p>&nbsp;  </p>
  <table width="889">
    <tr>
      <td width="140"><label>
        <input name="name" type="radio" id="name_0" value="0" checked="checked" />
        Common Name</label></td>
      <td width="6">&nbsp;</td>
      <td width="727">Click the letter below</td>
    </tr>
    <tr>
      <td><label>
        <input type="radio" name="name" value="1" id="name_1" />
        Scientific Name
        <input name="hide" type="hidden" id="hide" value="<?php echo $letter; ?>" />
      </label></td>
      <td>&nbsp;</td>
      
      <td><a href=""<?php $letter = 'A';?> onclick="document.form1.submit();return false">A
        
      </a><a href=""<?php $letter = 'B';?> onclick="document.form1.submit();return false">B
        
      </a></td>
    </tr>
  </table>
  
</form>

Open in new window

fastfind1Asked:
Who is Participating?
 
joep1978Commented:
Give this a try
<script type="text/javascript">
 
function formSubmit(p_letter)
{
        document.getElementById('hide').value=p_letter;
        document.form1.submit();
 
}
 
</script>
 
<form id="form1" name="form1" method="post" action="grass1.php">
  <p>   </p>
  <table width="889">
    <tr>
      <td width="140"><label>
        <input name="name" type="radio" id="name_0" value="0" checked="checked" />
        Common Name</label></td>
      <td width="6"> </td>
      <td width="727">Click the letter below</td>
    </tr>
    <tr>
      <td><label>
        <input type="radio" name="name" value="1" id="name_1" />
        Scientific Name
        <input name="hide" type="hidden" id="hide" value="<?php echo $letter; ?>" />
      </label></td>
      <td> </td>
 
      <td><a href="#" onclick="javascript:formSubmit('A');">A
 
      </a><a href="#" onclick="javascript:formSubmit('B')">B
 
      </a></td>
    </tr>
  </table>
 
</form>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.