/    Sign up×
Community /Pin to ProfileBookmark

Value of Select Box

I am trying to get the value of a select box (set to multiple).

I have tried:
document.all.FormName.FormField.selected.value
AND
document.all.FormName.FormField.value

But neither seem to work. Basically what I am trying to do is use a Javascript funtion to submit a go to another page (using location.href(‘….’)), with the value of a select box appended to the url as a url variable, but I just keep getting an error “Object doesn’t support this property of method”.

function down(){
location.href(‘index.cfm?report=repname&parent=’document.all.FormName.FormField.selected.value);
return true;
}

Thanks in adance.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisDec 09.2002 — For a multiple select, you will have to step through each option and test it's [font=courier]selected[/font] attribute.

[font=courier]var st = "";

var sl = document.formName.selectName.options;

for (var i in sl)

{if (sl[i].selected)

{st = (st == "") ? sl[i].value : " " + sl[i].value;}

}

[/font]
Copy linkTweet thisAlerts:
@themanglerDec 09.2002 — The following code will allow you to retrieve the value that is currently in the select drop-down field. It works in both IE and Netscape.

[COLOR=darkblue]document.formName.selectName.options[document.formName.selectName.selectedIndex].value[/COLOR]

[I](The formName and selectName in the code above should be change to your form and control names - leave 'selectedIndex' as it is.)[/I]

That should do the job for ya!

sampson
×

Success!

Help @jason spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...