Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing dropdown vars

Status
Not open for further replies.

Aeros

Programmer
Oct 7, 2002
166
US
Im trying to pass the values of two drop downs to a hidden field which already holds the item name (ItemDesc) of 'shirt' so that if a user picks 'red' and 'large' the ItemDesc value becomes 'shirt - red/large'. The question is can this be done in this single page or do I need a secondary page to process the vars and pass it? Ideally I would like to do it on this single page and just pass the 'ItemDesc' var with all three vars .

<form name="form1" method="post" action="process.php">
<select name="varColor">
<option value="red">red</option>
<option value="blue">blue</option>
<option value="green">green</option>
</select>
<select name="varSize">
<option value="small">small</option>
<option value="medium">medium</option>
<option value="large">large</option>
</select>
<br>
<input name="ItemDesc" type="hidden" value="shirt">
</form>

Thanks
 

So I would like it to dynamically gernerate the 'ItemDesc' field like this on this page before sending to the process.php page:
(if 'red' and 'large' were selected)

<input name="ItemDesc" type="hidden" value="shirt -red/large">
 
How reliable do you need this to be? You could add an onsubmit to your form (like onsubmit="return preSubmission( this );") and then gather the values and write them to the hidden field before submitting the form but if somebody turns Javascript off it's a dead duck.

Why not just create the string you need on the server? It's just as easy and it's much more reliable.

If you decide you still want to go ahead and do this client-side, something like this will do it:

Code:
function preSubmission( frm ) {

	var hidden = frm.elements[ "ItemDesc" ];
	var col = frm.elements[ "varColor" ];
	var size = frm.elements[ "varSize" ];

	hidden.value += " - " + col[ col.options.selectedIndex ].value + "/" + size[ size.options.selectedIndex ].value;
	return true;
}

HTH.

Oh, btw, you should really build some error checking into that if you decide to use it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top