Forum Moderators: open

Message Too Old, No Replies

Passing data from one form field to another in same form

Enter an alpha code in one field - put dollar amount in other

         

tomrockymtn

8:14 pm on May 14, 2008 (gmt 0)

10+ Year Member



Hi!

I have created a working registration form in php that writes the information to a MySql database. All is working fine.

Currently there are three radio buttons to select three standard registration types.

I now need to have a text box where the registrant can enter an alpha code such as "GCP" or "MCP" which is given by the organization to the registrant. When they enter this code it would need to place the registration fee associated with that code into another form field such as "0" or "250" which equals the dollar amount for that code.

I will then have that alpha code posted to the database. The dollar amount will populate a field that I will use in the totalling. That field is currently available and functioning if they were to type in an amount.

I have to use these codes and they can't be in a drop down menu otherwise folks could pick them and get around the regular registration.

I currently have six special codes and there will probably be more added.

I know I have seen javascript that can do the passing of data between fields (unless I was dreaming) but I can't find it after much searching so, I'm turning to the experts out there for help.

Thanks in advance for your time!

Tom

rocknbil

5:01 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard!


function popField() {
var ind = document.getElementById('code').selectedIndex;
var val = document.getElementById('code').options[ind].value;
document.getElementById('price').value=val;
}


<select name="code" id="code" onChange="popField();">
<option value="">Select</option>
<option value="250">GPC</option>
<option value="300">MCP</option>
</select>
<input type="text" style="border: none;" name="price" id="price" value="" onFocus="blur();">

Something like that should work, but you really need to duplicate the Javascript task on the server side. If JS is disabled, you'll get no value for price.

tomrockymtn

8:38 pm on May 15, 2008 (gmt 0)

10+ Year Member



Thanks for the welcome and thank you for the code!

This works great.

The thing I would like to do is to change the drop down box to a text box so they would have to type in the code like MCP and then a dollar amount would appear in another text box that corresponds to that code. Otherwise a regular registration person could pick the cheaper priced registration which was for someone "special" :)

Is that possible?

Thanks again for this!