469,647 Members | 1,789 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

is it possible to get options from list without selection

106 100+
i have a JS function which adds items to a list when the user clicks on a button ADD ITEM now i need to get all the items he added in the list without selecting them !! is that possible ?
i need to insert those items in the DB
any ideas ?
Nov 12 '08 #1
7 1481
gits
5,390 Expert Mod 4TB
of course ... you just need to loop over the options that a select-node contains. could you post an example and tell what you want to retrieve the values or the 'description' of the items ... or both? how do you want to transfer the data?

kind regards
Nov 12 '08 #2
jessy
106 100+
Well, this is my pretty simple JS function
Expand|Select|Wrap|Line Numbers
  1. function AddItem()
  2.     {   var opt = document.getElementById("List1");
  3.         var value=opt.options[opt.selectedIndex].text;
  4.         var newItem=document.createElement("option");
  5.         newItem.text=value;
  6.         document.getElementById("List2").options.add(newItem);
  7.   }
  8.  
and this is my List 2 (destination list) ==>
Expand|Select|Wrap|Line Numbers
  1. <select size="6" id="List2" name="list2[]" ></select>
these data are sent to DB.php which is supposed to take the posted data into the DB and thats the page at which i should loop through the options as u said but dont know how ??
Nov 12 '08 #3
gits
5,390 Expert Mod 4TB
not exactly what i meant ... you need to loop at the client and add the options to the postdata onsubmit of your form or do you do an ajax-call?
Nov 12 '08 #4
jessy
106 100+
i dont know if i get you But im doing this through onchange event for the select which submits the form
Expand|Select|Wrap|Line Numbers
  1.  select name="uniforms" onChange=this.form.submit();
and upon selection the user is presented with two list boxes with add to list and remove from list arrows ..so when he clicks on add to list(list2) and chooses all he wants from list1 to be added to list 2 he clicks on ADD button this button moves to the DB.php page which i was hoping to get the options in the list 2 WITHOUT selection ( just get all the items in there )
Nov 12 '08 #5
gits
5,390 Expert Mod 4TB
so as i understand ... you have a second submit then? and this form with the two lists just need to take care of your problem? while adding and deleting you have two options. you could use the iterate method to get all options in the list or you may have a hidden field that contains them ... just update this while adding deleting items ... the other option could always do this on submit of the second form.

kind regards
Nov 12 '08 #6
jessy
106 100+
Can u plz post some piece of code for any of the options u specified
Nov 12 '08 #7
gits
5,390 Expert Mod 4TB
ok ... here is an example for how to get all option-values of a list 'foo' onclick of a button:

[HTML]<html>
<script type="text/javascript">
function get_options() {
var n = document.getElementById('foo');
var l = [];

for (var i = 0, o; o = n.childNodes[i]; i++) {
if (/^option$/i.test(o.tagName)) {
l.push(o.value);
}
}

alert(l);
}
</script>
<body>
<select id="foo">
<option value="foo1">foo1</option>
<option value="foo2">foo2</option>
<option value="foo3">foo3</option>
<option value="foo4">foo4</option>
<option value="foo5">foo5</option>
</select>
<input type="button" onclick="get_options()" value="get options"/>
</body>
</html>
[/HTML]
now you just need to do anything you want with those values.

kind regards
Nov 12 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by glin | last post: by
3 posts views Thread by RRoberto | last post: by
15 posts views Thread by TJ Walls | last post: by
5 posts views Thread by srampally | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.