?
Solved

PHP submit form and update variable onclick

Posted on 2009-04-28
1
Medium Priority
?
1,933 Views
Last Modified: 2013-12-12
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

0
Comment
Question by:fastfind1
1 Comment
 
LVL 4

Accepted Solution

by:
joep1978 earned 2000 total points
ID: 24253621
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question