HighDots Forums  

Re: Javascript Multiple select menu

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Javascript Multiple select menu in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paul
 
Posts: n/a

Default Re: Javascript Multiple select menu - 08-01-2006 , 08:35 AM







kiran wrote:
Quote:
hi,
iam creating a multiselect menu in javascript the code for that is as
follows
"<select id=\"groups\" name=\"groups[]\" size=\"4\" multiple>"
"<option value=x>xyz</option>"
.
.
.
.
"</select>"
iam doing this completely in javascript. Its a dynamic menu. So how can
retrieve the values in javascript itself . if anyone knows kindly let
me know
try this:
<script>
var dynamicOpts = new Array(
new Option("xyz", "x"),
new Option("yzx", "y"),
new Option("zxy", "z"),
new Option("foo", "f"),
new Option("bar", "r"),
new Option("baz", "b")
);

function makeSelect(){
var theSelect = window.document.createElement("select");
arguments.callee.theSelect = theSelect;
theSelect.id = "groups";
theSelect.name = "groups[]";
theSelect.size = "4";
theSelect.multiple = "multiple";
var theOptions = theSelect.options;
for(var i=0;i<dynamicOpts.length;i++){
theOptions[theOptions.length] = dynamicOpts[i];
}
document.getElementById("genContFrm").appendChild( theSelect);
}
function showSelected(){
var opts = makeSelect.theSelect.options;
var selVals = "";
for(var i=0; i<opts.length;i++){
if(opts[i].selected){
selVals += opts[i].value + ",";
}
}
alert(selVals);
}
window.onload = makeSelect;

</script>

<form id="genContFrm">
<input type="button" onclick="showSelected()" value="show selected" />
</form>



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.