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

How to pass a value from Drop-down to Textbox...

Pass value to checkbox

How to pass a value from Drop-down to Textbox...

by  GUJUm0deL  Posted    (Edited  )
Hiya, folks...this script will pass a value from the drop-down select box to the textbox...
This can be done two ways: one is via the onClick even handler in the <form> tag and the other is in the <input button> tag...
The diff. is, the first way (<form> way) will pass the value as soon as the value is selected, while the later version (<input button> way) will only pass it after the user hits the button...

This is the <form> way:
[color red]
Code:
<html>
<head>
<title>Drop DOwn and Textbox</title>

<script language="javascript">
function displ()
{
  if(document.myFORM.valu.options[0].value == true) {
    return false
  }
  else {
document.myFORM.textfield.value=document.myFORM.valu.options[document.myFORM.valu.selectedIndex].value;
  }
  return true;
}
//-->
</script>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<table border="0" cellspacing="0" cellpadding="0" width="75%">
  <tr>
<td width="100%"><form name="myFORM" onClick="return displ();">
        <p> 
          <select name="valu" size="1">
		    <option value>Choose One</option>
            <option value="MT001">MT0001 | Copper Cable Shield 1</option>
            <option value="MT002">MT0002 | Copper Cable Shield 2</option>
            <option value="MT003">MT0003 | Copper Cable Shield 3</option>
          </select>
          <input type="text" name="textfield">
        </p>
</form>
</td>
</tr>
</table>
</body>
</html>
[/color]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top