kaiwhoeatspie
asked on
Referring to an HTML listbox (multiple select) using JavaScript
I have an HTML listbox in an ASP page in which users can select one or more values, as follows:
<select class='cInput' name="listbox" size=5 multiple STYLE='width:300px;'>
On submit a JavaScript function on the same page is called that referrences that listbox as follows:
lcValue =document.forms[formNo].li stbox.opti ons[docume nt.forms[f ormNo].lis tbox.selec tedIndex]. value;
formNo is passed into the function.
If I use "var lcValue = String(trim(Request.Form(" listbox")) );" in another ASP page using POST and more than one value has been highlighted in the box then lcValue automatically returns a list seperated by commas.
However the JavaScript code "document.forms[formNo].li stbox.opti ons[docume nt.forms[f ormNo].lis tbox.selec tedIndex]. value" only returns the first selected item in the listbox.
How can I get lcValue to return a comma seperated list in JavaScript?
<select class='cInput' name="listbox" size=5 multiple STYLE='width:300px;'>
On submit a JavaScript function on the same page is called that referrences that listbox as follows:
lcValue =document.forms[formNo].li
formNo is passed into the function.
If I use "var lcValue = String(trim(Request.Form("
However the JavaScript code "document.forms[formNo].li
How can I get lcValue to return a comma seperated list in JavaScript?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I will try your suggestions on Tuesday (weekend then national holiday in UK on Monday). Sorry that I can't test now.
ASKER
I gave Bustarooms the points because:
a) code is cleaner, function can be reused
b) it only creates a comma seperated list for selected option values, not all of them
a) code is cleaner, function can be reused
b) it only creates a comma seperated list for selected option values, not all of them
ok, why the B?
ASKER
Correct me if I am wrong but I think a B should be given for a question that has been answered correctly and to spec. An A is for a question that has been answered "beyond the call of duty", where extra special effort has been made beyond what was required.
Do you think that is not fair?
Do you think that is not fair?
to me, any help you get on this board, where someone takes the time to help you out is "beyond the call of duty"
Here's what EE thinks about grading
https://www.experts-exchange.com/help.jsp#hi73
Here's what EE thinks about grading
https://www.experts-exchange.com/help.jsp#hi73
ASKER
I stand corrected. An "A" it is. I will contact EE and ask them to upgrade.
var i
var lcValue
lcValue = ""
for(i=0; i<=document.forms[formNo].
{
lcValue = lcValue + document.forms[formNo].lis
}
lcValue = lcValue.substr(0,lcValue.l