View Full Version : Seeking form script that loads targeted pages on submit

02-12-2008, 06:18 PM
Hi, all!

I've been searching all morning for a form script that does the following:

1. User selects options in a form via radio buttons then presses 'submit'.

2. If radio buttons A & B are selected, page1.html loads on submit.

3. Alternatively, if radio buttons C & D are selected, page2.html loads on submit.

Does anyone know where to find such a script? I would prefer to use PHP but for my specific needs it has to be plain ol' Javascript, if possible.

Cheers ;)


02-12-2008, 08:57 PM
Apparently radio buttons don't have a selectedIndex or value property so thats annoying but its easy enough to get around by just looping through all the radio buttons in the collection.

Try this:

function goto(r)
for (i=0; i<r.length; i++)
if (r[i].checked) window.location = r[i].value;
<form onsubmit="goto(this.r);return false;">
<input type=radio name=r value="http://google.com">
<input type=radio name=r value="http://yahoo.com">
<input type="submit" value="">

02-12-2008, 09:24 PM
That'll work! Thank you very much! :)