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

Refresh textbox on listbox onchange

Status
Not open for further replies.

keijen

Programmer
Jul 12, 2001
16
AU
This is so basic it's embarrassing to ask, but I've never used one line of JS before.

I have a select listbox and when client uses it, I wish to refresh a text box conditionally according to the content selected in the listbox. The textbox is on the same form.

e.g.
Listbox option value is "A", Text is "Extreme".
I wish to show "Within 3 hours" in the textbox

Client selects 'Extreme" (or one of five other options) and from the options values I wish to pick appropriate text (from array or 'case' statement) and refresh the textbox.

Clues and samples will be appreciated.
TIA
keijen
 
There is an event called onChange associated with the listbox. This event is fired whenever the user selects an option from the listbox(does'nt get fired when the user just clicks on the selected option). You can call methods on this event.
For e.g.
<INPUT type=text name=txt1 value=&quot;&quot;>
<SELECT name=list1 onChange=&quot;fnChangeText(this,this.form);&quot;>
<OPTION>...</OPTION>
.
.
.
</SELECT>

<SCRIPT Language=&quot;Javascript&quot;>
function fnChangeText(objListBox,objForm)
{
var intSelIndex=objListBox.selectedIndex; // gives the index of the selected item.

if (objListBox[intSelIndex].value==&quot;A&quot;) // comparing the value of the selected option with some value
objForm.txt1.value=&quot;Whatever1&quot;;
else
objForm.txt1.value=&quot;Whatever2&quot;;
}
</SCRIPT>

for further assistance contact me at pankaj_vohra@inf.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top