I have been reading several posts realted to this matter here on Stack Overflow and been reading the W3 Schools tutorials on Javascript and HTML forms.
I am creating an XHTML
form with required fields for users to submit personal data (Name, Address, Phone). I want the onsubmit
attribute to pass each input value as an argument to my external javascript function website_form_error()
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<script src="http://othermindparadigm.com/web_frm_err.js" type="text/javascript"></script>
</head>
<body>
<p class="mid" id="frm_responder"> </p>
<form action="/webformmailer.php" method="post" onsubmit="javascript:website_form_error(document.getElementById('Name').value,document.getElementById('Address').value,document.getElementById('Phone').value)">
<p>
* Name <input class="norm" type="text" name="Name" />
* Address <input class="norm" type="text" name="Address" />
* Phone <input class="norm" type="text" name="Phone" />
</p>
<input type="submit" />
</form>
</body>
</html>
The form has an external JavaScript file to be called when submitted. /web_frm_err.js
function website_form_error(Name,Address,Phone)
{
var = Name,Address,Phone,response ;
response = (Name,Address,Phone == undefined)
?
"Your specifications have been sent to Other Mind Paradigm"
:
"Form incomplete. You must fill in all required fields." ;
document.getElementById("frm_responder").innerHTML = response ;
}
I want the website_form_error()
function to cancel the form submission and redirect back to the form and insert a message into <p id="frm_responder">
when the user has not filled in all of the required fields.
My website_form_error()
function does not yet have a way to cancel the submission and the text to be inserted does not trigger. I'm sure there is something wrong with my Javascript. Any answers?