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!

Form question 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Hi,

I have a page that reads two columns from a database ( part number and part description ). It then displays a form with the part numbers in a list box and an empty text box beside it. What I would like to be able to do is automatically polulate the text box with the part description once the user selects a part number from the list. Can someone please advise me on how to do this.
 
Either you do it completely on the client using Javascript or you can refresh the page and write the new value to the textbox on the server. Here is an "example" of how to do it on the client side:
<select id=&quot;select1&quot; name=&quot;category&quot; onchange=&quot;updateDropdown()&quot; size=&quot;1&quot;>

If you want to do it server side then you could call document.location with a querystring that tells your ASP-page what to write in the box or else:

function updateDropdown() {
var select = eval(document.choose_category.category.selectedIndex);
var catId = document.choose_category.category.options[select].value;
var d = document.formname.inputname;


if (catId == 'nochoice'){
} else if (catId == '1'){
d.value='this is a wonderful product...';
} else if (catId == '2'){
d.value='this is bad for you';
} // here you can continue with more else if

} // end function



Google is you friend.
 
jonelf,

Thanks for the response. I am new to Javascript but that looks like it will work for me with a bit of tweaking. I have another question: Is there a function in JS that will remove trailing spaces from a string i.e. a &quot;trim&quot; function.
 
jonelf,

Forget my last question - I figured it out ( I just trimmed the strings in my ASP code before I outputted it back to the browser. )

The code you supplied works a charm. :)

Thanks alot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top