Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Active Server Pages (ASP)
Expertise: Beginner
Dec 16, 1999

Dynamically Insert Text Into a Text Box

Question:

How can I provide the user with a combo box and based on his selection populate the data in a text box? The data has to come from a back-end database. The catch is that the combo box and the text box are in the same form.

Answer:

You can do this easily with client-side JavaScript. First, get the data for the combo box and at the same time, get the corresponding data for the text box from your back-end database also. If possible, store the text data as the VALUE property of the combo box. Otherwise, store it in a client-side JavaScript array with an index matching the value property of the combo box item, or some other match. On the ONCHANGE event of the combo box, set the value of the textbox to the text data value. To get the value of the currently selected combo box, use this code:

// get selected index
var i = document.formname.comboboxname.selectedIndex;
// get value of selected index
var v = document.formname.comboboxname.options[i].value;
// set value to text box
document.formname.textboxname.value = v;
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date