Get values from a select that aren't selected on a post?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Jhorra
Forum Newbie
Posts: 24
Joined: Mon Aug 18, 2003 1:00 am

Get values from a select that aren't selected on a post?

Post by Jhorra »

I have two select boxes, and using javascript you select an item from one, and move it to the other. Then I want all the options in the second select box on the post. However, since they aren't selected, they don't post. Anyone have a suggestion on what I can do? I tried to put an on click event on the submit button that would loop through and select them all, but it didn't seem to work. Any other ideas? Maybe I could place a hidden element and add the values to it?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Wrong forum -> Client Side
You can set an onsubmit handler for the second form and set the select attribute to true for all options there.
Jhorra
Forum Newbie
Posts: 24
Joined: Mon Aug 18, 2003 1:00 am

Post by Jhorra »

volka wrote:Wrong forum -> Client Side
You can set an onsubmit handler for the second form and set the select attribute to true for all options there.
Can you move this post for me?

Also, I did try something like you said, and put an onclick event on my submit button then used this for the function is calls

Code: Select all

var selected_songs = document.getElementById("selected_songs");
for(var i = 0;i< selected_songs.length; i++)
{
   selected_songs.options[i].selected = true;
}
But that didn't seem to do it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Either use a javascript debugger or add some (annoying) debug output like

Code: Select all

var selected_songs = document.getElementById("selected_songs");
alert(selected_songs);
for(var i = 0;i< selected_songs.length; i++)
{
	alert(i);
	selected_songs.options[i].selected = true;
}
return true;
Jhorra wrote:Can you move this post for me?
No, but it's likely a moderator will do so sooner or later ;)
Post Reply