Page 1 of 1

passing all elements in a select box at once

Posted: Thu May 12, 2005 6:05 am
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?

Posted: Thu May 12, 2005 6:56 am
by JayBird
how is you select box generated?

Posted: Fri May 13, 2005 7:03 am
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.