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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two Combo boxes, one huge headache!!!

Status
Not open for further replies.

LyallJ

MIS
Jul 18, 2001
124
US
Ok, heres what i am tring to do. Prolly easy for some of you folks..but it is killin me..

I need to have 2 drop down boxes that have diffent colors in them, in a form. When user presses Submit button, i need these to colors to equal one value.

ie, i need to pass this (look at descr part ;-))


with the descr part being what the 2 drop down boxes equal. I can get one of the drop down boxes like this..

<form action="phpcart/phpcart.php" method="GET">
<input type="hidden" name="action" value="add">
<input type="hidden" name="id" value="105">
<select size="1" name="descr">
//this is colorone
<option value="Green">Green</option>
<option value="Blue">Blue</option>
<option value="Red">Red</option>
//need to have another combo box here that adds
//second color to the descr field
</select>
<input type="hidden" name="price" value="0.00">
<input type="hidden" name="quantity" value="1">
<input type="submit" value="Add to Basket">
</form>


Really drowning in this one........
 
Code:
<style>
.grey{
background-color:#f7f7f7;
}
.white{
background-color:white;
}
</style>
<form action="phpcart/phpcart.php" method="GET">
<input type="hidden" name="action" value="add">
<input type="hidden" name="id" value="105">
<select size="1" name="descr">
  <option class="grey" value="Green">Green</option>
  <option class="grey" value="Blue">Blue</option>
  <option class="grey" value="Red">Red</option>
  <option class="white" value="Green">Black</option>
  <option class="grey" value="Blue">Orange</option>
  <option class="white" value="Red">Purple</option>
</select>
<input type="hidden" name="price" value="0.00">
<input type="hidden" name="quantity" value="1">
<input type="submit" value="Add to Basket">
</form>

Pretty cool, huh? ;).

Rick

 

I think that this should do what you're after:

Code:
<html>
<head>
<script type="text/javascript">
<!--
	function makeDescr()
	{
		with (document.forms.myForm) descr.value = descr1.options[descr1.selectedIndex].value + descr2.options[descr2.selectedIndex].value;
	}
//-->
</script>

</head>
<body>
<form name="myForm" action="phpcart/phpcart.php" method="GET">
	<input type="hidden" name="action" value="add">
	<input type="hidden" name="id" value="105">
	<input type="hidden" name="descr" value="">
	<select size="1" name="descr1">
		<option value="Green">Green</option>
		<option value="Blue">Blue</option>
		<option value="Red">Red</option>
	</select>
	<select size="1" name="descr2">
		<option value="Green">Green</option>
		<option value="Blue">Blue</option>
		<option value="Red">Red</option>
	</select>
	<input type="hidden" name="price" value="0.00">
	<input type="hidden" name="quantity" value="1">
	<input type="submit" onclick="makeDescr();" value="Add to Basket">
</form>
</body>
</html>

Just ignore the descr1 and descr2 fields that also get passed.

Personally, I think passing descr1 and descr2 and doing the concatenation server-side would be far better, however. It's a no-brainer, and will also mean that non-Javascript users won't be affected (and before this starts a stats war, I'm only suggesting a server-side fix because it would be so easy to do in this particular case).

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top