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

simple example; populate textbox based on pulldown

Status
Not open for further replies.

CFeyrer

MIS
Jul 10, 2003
54
0
0
US
Can I have Javascript trigger a textfield to populate with a given value based on the content of a pulldown?
For example, if pulldown=M then textbox='Mr' if pulldown=F then textbox='Ms'

Thanks for your assistance.
PS I would love for this to work without refreshing the page/losing form data!
 
In your dropdown, add an onchange event:

Code:
<select onchange='updateTextBox(this.value)'>

Create a function:
Code:
<script>function updateTextBox(val)
{
 if(val == "something")
 {
  document.forms['myForm'].elements['myTextBox'].value = "something based on something";
 }
 else if(val == "something else")
 {
  document.forms['myForm'].elements['myTextBox'].value = "something based on something else";
 }
}
</script>

'make sense?

This assumes your form elements are in FORM tags and the FORM is NAMEd 'myForm' and the text box is NAMEd 'myTextBox'

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top