View Full Version : submit form problem

10-03-2012, 03:01 AM
Wasn't sure where to post this as i am not sure what's causing the problem...

I have an HTML form that validates with an onSubmit for javascript validation followed by and action:... which submits the the form into a database using php. at first the form submitted no problem but now that i put the js in the action doesn't seem to run.

Do these usually clash? Do I have to do both with the same language?

The javascript is and external file, in case that changes anything.

Old Pedant
10-03-2012, 03:03 AM
??? You can't use JavaScript in the action="..." attribute. You can ONLY specify the TEXT name of the target page.

If that's not what you meant that you did, show us your actual code.

10-03-2012, 03:15 AM
sorry about that. What I was tryin to explain is in the action=" ", I call php and call javascript in the onSubmit in the same form:

<form name="client_add" method="post" onsubmit="return validateForm();" action="client_save.php">
<label>First Name</label><br />
<input type="text" name="first_name" /><br />
<label>Last name</label><br />
<input type="text" name="last_name" /><br />
<label>Password</label><br />
<input type="password" name="password" /><br />
<label>Confirm Password</label><br />
<input type="password" name="confirm_password" /><br />
<label>Phone Number</label><br />
<input type="text" name="phone_number" /><br />
<label>Email</label><br />
<input type="text" name="email" /><br />
<input type="submit" value="save" />

I didn't post code because I wasn't sure exactly what code would be most useful.

Old Pedant
10-03-2012, 04:33 AM
That looks right, except that you gave a name to the <form>, which is obsolete.

Now go look in the other thread, where I commented on how you could/should validate.

10-03-2012, 04:37 AM

10-03-2012, 04:59 AM
along with all the other advice that you haven't followed, your brackets are still screwed up.

function validateForm() {
var fName = document.forms["client_add"]["first_name"].value;
var password = document.forms["client_add"]["password"].value;
var confirmPassword = document.forms["client_add"]["confirm_password"].value;
var phoneNumber = document.forms["client_add"]["phone_number"].value;
var email = document.forms["client_add"]["email"].value;
var x=document.forms["client_add"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (fName==null || fName==="") {
alert ("You must enter a name");
return false;
if (password==null || password==="") {
alert ("You must enter a password");
return false;
if (password!=confirmPassword) {
alert ("Passwords do not match");
return false;
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){
alert("Not a valid e-mail address");
return false;