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

populating div onchange of select box

Status
Not open for further replies.

spastica

Programmer
Sep 27, 2002
72
GB
I have a dropdown menu with various options. I would like to create a function where if one of the options is selected, a div on the page becomes populated with a text box.

I am using onchange on the dropdown menu to call in the following function, and am getting the error "'referralMeth' is null or not an object"


function showletterRefbox(form)
{
if(form.referralMeth.value=="Letter in post")
{

document.getElementById('referralMeth_letterRefNo').innerHTML = "Please enter the reference number from your letter: <input maxlength=\"60\" size=\"15\" type=\"text\" name=\"referralMeth_letterRefNo\">";

}


}

any ideas why? I can't figure out how to make it work...what am I doing wrong?
 
I wouldimagine the cause is your use of the reserved word form as a parameter. How about a minor change to the way you are doing things?

In your onchange="" code (for the select box) how about you change it to:

Code:
onchange="showletterRefbox(this.form.referralMeth.value)"

This will pass the actual value of the textbox named referralMeth to the function. Change the variable name in your function to something like:

Code:
function showletterRefbox(formData)     
{
 if(formData=="Letter in post")...

Hope that gets you started!
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top