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

Populate a field based on selection

Status
Not open for further replies.

n0795

Programmer
Jul 30, 2001
136
US
I have run into a problem this code does work but instead of displaying what shows up in the dropdown box its shows the catergories ID number in the title field.
It gets this ID number from the database.
Thanks
I have been told that I could use JScript to do a lookup of the ID number and change it to its name.
Is there anyone who can show me how
Please.
In the drop down box it shows a list of names from a database when someone selects a name I want that name to go into the title field,but instead of the name going in the tilte field the ID number for that name goes in...
This code wasnt mine to start off with so any help would be great...


<form name=&quot;add&quot; action=&quot;addlink.asp&quot; method=&quot;post&quot; onsubmit=&quot;return validate(this)&quot;>

<select name=&quot;category&quot; onChange=&quot;javascript:populateTitle()&quot;>

<script language=&quot;javascript&quot;>
function populateTitle() {
var listBox = document.forms[&quot;add&quot;].elements[&quot;category&quot;];
var titleText = document.forms[&quot;add&quot;].elements[&quot;title&quot;];
for(i=0; i<listBox.options.length; i++) {
if (listBox.options.selected) {
titleText.value = listBox.options.value;
}
}
}
</script>

<input size=&quot;50&quot; name=&quot;title&quot; value=&quot;&quot;>
 
So onChange populateTitle is called - which is supposde to take the name and put it it in the title, right?
Well it seems that your asp page is populating the options with a value corresponding to the ID, and the name is the text - so you can either change the vaue that the asp script puts in there

or

instead of taking the value - take the text from the option.

function populateTitle() {
var listBox = document.forms[&quot;add&quot;].elements[&quot;category&quot;];
var titleText = document.forms[&quot;add&quot;].elements[&quot;title&quot;];
for(i=0; i<listBox.options.length; i++) {
if (listBox.options.selected) {
titleText.value = listBox.options.text;
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top