Hi,

Im trying to make the price appear in a text box in a form when the user selects the quantity from a drop down box. The price is fixed at 38.50. Any help is highly appreciated, here is the code in my form (I havent attempted any javascript yet - and Im sure my code for the form is bad too!) :

<form action="" method="post">

 <tr align="left">
              <td width="118"><span class="style3">Quantity</span>
                  <select name="Product 1" size="1">
                    <option selected="selected">0 </option>
                    <option>1 </option>
                    <option>2 </option>
                    <option>3 </option>
                    <option>4 </option>
                    <option>5 </option>
                    <option>6 </option>
                    <option>7 </option>
                    <option>8 </option>
                    <option>9</option>
                  </select>
                  <input type="hidden" name="Product 1" value="38.50" />
<input name="hidden" type="text" value="Price" size="1" /></td>
				  </tr>
</form>

Here you go! Please don't forget to marked your thread solve, if it does solved the issue! Thanks!

<html>
<head>
<title><!--Sample--></title>
<script type="text/javascript">
<!-- BEGIN HIDING

document.onchange = function( e )
{ e = e ? e : window.event;
  t = e.target ? e.target : e.srcElement;
if (( t.name ) && ( t.name == 'product1' )) 
{ var thisPrice = product.price;
  var thisTotal = product.total;
  thisTotal.value = '$' +  t.selectedIndex * parseFloat (thisPrice.value); }
}

// DONE HIDING --> 
</script>
</head>
<body>

<br />

<form name="product" action="#" onsubmit="return false;"> 
<tr align="left">    
<td width="118">
<span class="style3">Quantity</span>     
<select name="product1" size="1">     
<option>0</option>     <option>1 </option>    <option>2 </option>     <option>3 </option>     <option>4</option>     <option>5 </option>    <option>6 </option>     <option>7 </option>     <option>8</option>     <option>9</option>    
</select>     
<input type="hidden" name="price" value="38.50" />&nbsp;<input name="total" type="text" value="0" size="5" style="text-align: center;" />
</td> 
</tr> 
</form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.