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

Code to transfer value from List meu to text field

Status
Not open for further replies.

Lil8

Technical User
Oct 24, 2003
42
GB
I am trying to write code that will transfer a value selected in a list menu (in a form) and put into a text field ( to be used in a calculation )
Will I need to use a onclick javascript to do this and
how do I set the focus of the text box ?

thanks Nic
 
The code below will need tweeking to your own purpose but it should give you the idea

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
function sumup(){
if (document.forms.form1.painting.value == "0"){
paintval=0;
}
if (document.forms.form1.painting.value == "painting1"){
paintval=1;
}
if (document.forms.form1.painting.value == "painting2"){
paintval=2;
}
if (document.forms.form1.painting.value == "painting3"){
paintval=3;
}
quantval = document.forms.form1.quantity.value;
mountval = document.forms.form1.mounting.value;
totalval = (paintval*quantval) + (mountval*quantval);
document.forms.form1.total.value = totalval;
}
</script>
</head>

<body>
<form name="form1" method="post" action="">
  <p>
    <select name="painting" id="painting" onChange="return sumup();">
      <option value="0" selected>** Please select **</option>
      <option value="painting1">Painting 1 - &pound;1</option>
      <option value="painting2">Painting 2 - &pound;2</option>
      <option value="painting3">Painting 3 - &pound;3</option>
    </select> 
  Which Painting<br>
  <input name="quantity" type="text" id="quantity" value="0" size="5" onChange="return sumup()">
How many?<br>
<select name="mounting" id="mounting" onChange="return sumup()">
  <option value="0">** Pease Select **</option>
  <option value="2.50">Canvas - £2.50</option>
  <option value="3.99">Stretched - £3.99</option>
  <option value="4.99">Framed &amp; Stretched - £4.99</option>
</select> 
Mounting Options?
</p>
  <p>
    <input name="total" type="text" id="total" value="0" size="8" readonly>
Total Cost (Quantity * (Painting choice + Mounting cost)) </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

[Peace][Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top