|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do i select all the values in a dynamically generated select box(multiple)
How do i select all the values in a dynamically generated select box(multiple) on submit?
-------------------------------------------------------------------------------- Im Sorry if this has been addressed before. I couldnt find an asnwer. I am allowing the site user to populate a multi select box with email addresses. I want to be able to select all the values in the multi select on form submit, because I can't expect the user to do so. Is there a javascript function that I can use to accomplish this? Thanks for your time and help good people ![]() |
|
#2
|
||||
|
||||
|
You also can't rely on the user having JavaScript enabled on his/her
machine, in which case, your form will never get filled in properly. Do this on the server instead. |
|
#3
|
|||
|
|||
|
Why don't you store the email addresses in a textarea or hidden input instead?
|
|
#4
|
|||
|
|||
|
Loop through the multiple select element
I would suggest that you simply loop through the multiple select element and set their selected attribute to true:
function loop_select() { for(i=0;i<=document.your_form.name_of_element.length-1;i++) { document.your_form.name_of_element.options[i].selected = true; } } Simple as that. You could also go all fuzzy and nice by defining an array or even an object that could be invoked and changed by an event listener attached to the textfield (I presume) where the user initially states the values that populate the multiple select element. Then simply assign this stringefied array to the value of a hidden field prior to submission. Yes, that would be nice. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > How do i select all the values in a dynamically generated select box(multiple) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|