Entry
Can I SUBMIT a FORM to a DYNAMIC URL based on the value of a RADIOBUTTON ?
Mar 24th, 2003 21:49
Indrayani Vaze, James, Jean-Bernard Valentaten, Mark Paschal, Anonymous,
Mark Paschal wrote:
> Yes.
Ok, since this answer is correct, but does not explain how, I'll give
it a try. If you find any bugs, please correct them!
Let's say you have a form named "myForm", containing two radiobuttons
("radio1" and "radio2"). It also contains a submit button (which is an
input-tag with the type "button", don't use a type "submit" button),
with it's onClick event triggering the following function:
function mySubmit()
{
//This gets the value of the checked radiobutton
//if any is selected. If no one is selected it returns
// "unchecked"
var radioValue = document.myForm.radio1.checked?
document.myForm.radio1.value:
(document.myForm.radio2.checked?
document.myForm.radio2.value:
"unchecked");
//Now if any radiobutton was checked we change the action of the
//form, corresponding to the checked radiobutton and submit the
//form. If not, we alert the user
if (radioValue != "unchecked")
{
document.myForm.action = radioValue;
document.myForm.submit();
}
else
alert("Please select any of the radiobuttons before submitting");
}
I hope that will help you,
Jean
hello,
call a function on submit that would contain
var URL=path+document.forms[0].radio.value
window.href.URL=URL
hope it will help
Indrayani