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

Dropdown Box and Nothing Selected

Status
Not open for further replies.

bobbybrown69

Programmer
Jun 11, 2003
15
US
What I am trying to figure out is how to know whether the user has chosen something from the descript_" + vid + " dropdown box below? I need to only add
+ ' ' + comSignature
to document.forms[0].elements['linerTextAndDescriptionAdj_" + vid + "'].value
if someone has chosen something from the Description dropdown. So if the dropdown box still says
-- choose description --
don't add
+ ' ' + comSignature
-----------------------------
oNewTd13.innerHTML = "<select class=copy style='background-color: #FFFFFF' onchange=\"document.forms[0].elements['linerTextAndDescriptionAdj_" + vid + "'].value = linerText + ' ' + this.options[this.selectedIndex].innerHTML + ' ' + comSignature; document.forms[0].elements['DescriptionAdj_" + vid + "'].value = this.options[this.selectedIndex].innerHTML;\" name=descript_" + vid + "><option value=''>-- choose description --</option>" + descriptionAdjOptions + "</select>";
oNewTd13.innerHTML += "<input type=hidden name=linerTextAndDescriptionAdj_" + vid + " value=''>";
oNewTd13.innerHTML += "<input type=hidden name=DescriptionAdj_" + vid + " value=''>";
-----------------------------
Things work with the onchange= but how do I know if the user doesn't choose anything from the dropdown choices and to not include + ' ' + comSignature if they don't choose anything?

document.forms[0].elements['DescriptionAdj_" + vid + "'].value is populated with the Description choice.
 
You can test the selectedIndex for the dropdown to determine if anything was selected. If it is 0 (the first item in the list) then assume that they haven't chosen anything (maybe name the 1st item Select from below or something).

You can expect that if they have javascript turned on, and choose something from the list (except for the 1st item) then the onchange will fire and do whatever you have told it to.

I've assumed that you are not setting the default option in the select to anything, and as such it defaults to the first element (the 1st item).

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top