473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

is it possible to get options from list without selection

106 New Member
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 1721
gits
5,390 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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 New Member
Can u plz post some piece of code for any of the options u specified
Nov 12 '08 #7
gits
5,390 Recognized Expert Moderator Expert
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

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

Similar topics

5
by: glin | last post by:
Hi there, does anyone know how to use smarty to generate a selection list without PHP assigning a array? eg. a list for selection minutes, but without php to assign a 1~60 array into smarty. ...
7
by: jason | last post by:
Is there a way - possibly a disconnected rs? - to update the contents of an existing pulldown on a page without having to re-submit the page for the user to see the pulldown populated with an...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
7
by: John C | last post by:
I am working with an HTML-based form that uses a select element that requires about 200 options. Is there a way that I can load, or select one of these options from a file, rather than hardcode...
3
by: RRoberto | last post by:
Goodmorning, Is it possible to edit a combobox like a textbox? I will appreciate any suggestion . Thank You Roberto
10
by: JL | last post by:
Does anyone have any ideas on this please? I don't know how to evaluate the no-blank selections against each other from a form as follows: . I have a form with 6 dropdown fields, each...
15
by: TJ Walls | last post by:
Hello All, Is it possible to create a <select> element with no selected options? I have tried setting the selectedIndex attribute to -1, but as far as I can tell this only works for <select...
4
by: Colleyville Alan | last post by:
I am trying to use a list box to allow users to select items, the results are queried based on the selection and written to a spreadsheet. If the item already exists on their current spreadsheet,...
5
by: srampally | last post by:
I need the capabilty to hide/show a selection list, just the way its done at http://www.lufthansa.com (place the cursor over "Group Companies"). However, I am looking for a javascript that is much...
2
by: jessy | last post by:
My Problem is that i have a list which contains some items added by the user from another list now i need this second list to be added to the Database but without the user selecting all the items ......
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.