Here 开发者_Python百科is the code. Functionally it works fine, but won't collect the data when firefox used.
Javascript
var redirectPage = "rsvp.html"; //CHANGE redirected page here.
function submitform() {
document.bandform.submit(); //CHANGE name of form here
RedirectWithFormValues();
}
function RedirectWithFormValues() {
var band = GetRadioValue("nameband"); //CHANGE name of variable here
window.location = redirectPage + "?band=" + band; //CHANGE name of new variable here
}
function GetRadioValue(rdName) {
var rd = document.getElementsByName(rdName);
for (var i = 0; i < rd.length; i++) {
if (rd[i].checked) {
return rd[i].value;
}
}
}
HTML Markup
<form action="" method="post" name="bandform">
<input name="nameband" type="radio" value="Noon - 1pm" checked="checked" class="radio1">
<input name="nameband" type="radio" value="5pm - 6pm" class="radio2">
<input type="button" value="" class="button1" name="" onclick="javascript:submitform();">
< /form>
Any help would be appreciated!
This is likely not going to work in most browsers:
function submitform() {
document.bandform.submit(); //CHANGE name of form here
RedirectWithFormValues();
}
What you ought to do is something like this with jQuery:
$('#bandform').ajaxForm({
success: RedirectWithFormValues
});
That will do an AJAX submit on the form, and when complete, call the RedirectWithFormValues function.
Instead try the code below,
Aspx section,
<form name='bandform' method='post' action='' onsubmit='return submitform();'>
<input type='submit' value=' Send Message ' />
</form>
Javascript Section,
function submitform() {
document.bandform.submit();
RedirectWithFormValues();
return true;
}
Hope this helps...
why not just set the redirectPage value (with band selection) to the form's action element, and then just let the form submit (return true from submitForm()) instead of doing the redirect?
function submitform() {
setFormAction();
return true;
}
function setFormAction() {
var band = GetRadioValue("nameband");
var redirectUrl = redirectPage + "?band=" + band;
document.getElementById('bandform').action = redirectUrl;
}
function GetRadioValue(rdName) {
var rd = document.getElementsByName(rdName);
for (var i = 0; i < rd.length; i++) {
if (rd[i].checked) {
return rd[i].value;
}
}
}
<form action="" method="post" id="bandform" name="bandform">
<input name="nameband" type="radio" value="Noon - 1pm" checked="checked" class="radio1">
<input name="nameband" type="radio" value="5pm - 6pm" class="radio2">
<input type="submit" name="" onClick="submitform()" value="Submit" />
< /form>
精彩评论