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

How do I populate a text box with a dropdown value? 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Joined
Sep 8, 2005
Messages
603
Location
US
I've tried several methods mentioned on this subject but can't get any of them to work. Attached is my latest attempt.

Thanks in advance.
Lyndon

Code:
<form name="MyForm" action="MyInvoice.htm" method="post">
	Amount: 
	<input type="Text" name="Amount" size="10" value="55">
	<br>
	Type: 
	<select name="ProductType">
		<option value="33" onchange="FillAmount();">Product A</option>
		<option value="55" onchange="FillAmount();">Product B</option>
	</select>
	<input type="Submit" value="Print"
</form>

<script type="text/javascript" language="JavaScript">
	function FillAmount()
	{
		MyForm.Amount.value = MyForm.ProductType.options[MyForm.ProductType.selectedIndex].value;
	}
</script>
 
Code:
<form name="MyForm" action="MyInvoice.htm" method="post">
    Amount:
    <input type="Text" name="Amount" size="10" value="33" />
    <br>
    Type:
    <select name="ProductType" [!]onchange="FillAmount()"[/!]>
        <option value="33">Product A</option>
        <option value="55">Product B</option>
    </select>
    <input type="Submit" value="Print" />
</form>

<script type="text/javascript" language="JavaScript">
    function FillAmount()
    {
        document.forms["MyForm"].elements["Amount"].value = document.forms["MyForm"].elements["ProductType"].options[document.forms["MyForm"].elements["ProductType"].selectedIndex].value;
    }
</script>

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Thank you kaht. (for the umph-tenth time) LOL

 
not a problem

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top