Forum Moderators: open

Message Too Old, No Replies

Passing multiple select box entries to function

multiple select box values passed to javascript for page reload

         

jenwen

4:37 am on Apr 19, 2007 (gmt 0)

10+ Year Member



Hi! I'm trying to write a function that will onclick, redirect a page to itself and carry over previously entered form values. One of my boxes is a multiple select box. When I reference the value, it just passes the first selected value.

This is the function (simplified to show only the problem child):

function enableCDRL()
{
var cdrlref="search.cfm?+"auth="+document.searchform.authorstr.value;
window.location.href =cdrlref;
}

I selected two values, and activated the function...

And this is the url bar I get:

[127.0.0.1:8500...]

Eek! How do I get the other selected values to pass? Is it possible to do this without using a form submit?

Jen

daveVk

6:53 am on Apr 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Think you need to loop thru each option ie document.searchform.authorstr.childNodes and for each selected option add value to request.

jenwen

8:03 am on Apr 19, 2007 (gmt 0)

10+ Year Member



Actually, I *JUST* figured it out. LOL. Thanks VERY much!

Jen

Dabrowski

10:59 am on Apr 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a much easier way...don't put an action on your form tag:

<form name='myForm' method='GET'>

This will cause it to submit to itself. Next on your select tag make it actually submit the form:

<select name='mySelect' onChange='document.myForm.submit();'>

Now that should send though every form field as normal, but you have the problem that when you actually hit 'Submit' it doesn't go to the right page. Do this:

<input type='submit' value='Send Form' onClick='document.myForm.action = "search2.cfm";'>

That way you need no extra JS code at all, just those 2 events.