passing all elements in a select box at once

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

passing all elements in a select box at once

Post by shiznatix »

i have a select box and i want to pass every option of the select box with post not just what is selected in that box. I have it so there is a big list of options in 1 select box then you can move the diffrent options to other select boxes on the site depending on where you want to put them. when the user hits submit i want to take all the values from all the select boxes and use php to get them via post.

i was thinking maybe do a onclick on the submit button to take all of the options from list A and make a hidden field like
<input type="hidden" name="A[]" value="option1">
<input type="hidden" name="A[]" value="option2">

then for list B
<input type="hidden" name="B[]" value="option3">
<input type="hidden" name="B[]" value="option4">

but thats just a idea...anyone know how to do any of this?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

how is you select box generated?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

never mind i fixed it...here is how i did it
i had a hidden field for each select box i wanted to pass all the info of and did this

Code: Select all

function getValues (select) {
  var r = new Array();
  for (var i = 0; i < select.options.length; i++)
      r&#1111;r.length] = select.options&#1111;i].value;
  return r;
}
then the submit button

Code: Select all

<input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;submit&quote; 
    onClick=&quote;this.form.basic_val.value = getValues(this.form.basic); this.form.medium_val.value = getValues(this.form.medium); this.form.specialist_val.value = getValues(this.form.specialist); this.form.expert_val.value = getValues(this.form.expert);&quote;>
as you can see i had 4 lists. the output was the $_POST[basic]->#,#,# the # being the option value. worked quite well.
Post Reply