Jump to content

Recommended Posts

Hi,

 

I have some javascript defined that is working correctly to check if one of the two radio buttons checked prior to allowing submit to complete.

However, I have a 2nd button which performs a 'redirect' which I can't figure out how to include on that JS validation process to echo 'error3' if neither radio button not checked prior to the defined redirect for that button.

 

Can someone advise how I can include the 'ddsumbit' button to to that JS validation script to ensure one of the radio buttons are checked before redirecting to link?

 

The code is below - thx!

 

<script type="text/javascript">
// script.js handle the form submit event on form (below) entitled form.html
function prepareEventHandlers() {
document.getElementById("form3").onsubmit = function() {
	if ((document.getElementById("func_0").checked == true) || (document.getElementById("func_1").checked == true)) {
		document.getElementById("error3").innerHTML = "";
		// to STOP the form from submitting
		return true;    // uncomment this line to have submit working
		//return false;    // remove line when using in the real world
	} else {
		// reset and allow the form to submit
		document.getElementById("error3").innerHTML = "A SELECTION IS REQUIRED";
		return false;
	}
};
}

// when the document loads
window.onload =  function() {
prepareEventHandlers();
};
</script>

 

Here's the radio buttons & the two buttons code that is defined within the form:

 

<form action="index.php" method="post" name="form3" id="form3">
<span id="error3"></span>
<input type="radio" name="func" value="work" id="func_0" />
<input type="radio" name="func" value="nonwork" id="func_1" />

<input type="submit" name="submit3" id="submit3" value="next>" tabindex="15" />
<input type="button" name="ddsubmit" id="ddsumbit" onClick="location.href='cancel.php'" value="decline" tabindex="20" />
</form>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.