Ninjakreborn Posted April 28, 2006 Share Posted April 28, 2006 what's wrong with this.Form below[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>php test page</title><script src="freelancebusinessman.js"></script></head><body>Please fill in the following form and submit the information to me:<br /><form name="formtest" action="formprocessor.php" method="post">First Name:<input name="firstname" type="text" maxlength="30" /><br />Last Name:<input name="lastname" type="text" maxlength="30" /><br />Age:<input name="age" type="text" maxlength="3" /><br />Please enter desired Username:<input name="username" type="text" maxlength="35" /><br />Please verify Username:<input name="verifyusername" type="text" maxlength="35" /><br />Please enter desired password:<input name="password" type="password" maxlength="25" /><br />Please verify your password:<input name="verifypassword" type="password" maxlength="25" /><br />Now for the section to tell me a little bit about yourself.<br />Please enter information about your personal life below:<br /><input name="personallife" type="text" /><br />Please enter all the programming languages you currently know:<br /><input name="languages" type="text" /><br />Please enter all your past experiences below:<br /><input name="experiences" type="text" /><br />Please check all that apply:<br />I am:<br />Perfect:<input name="iam[]" type="checkbox" value="perfect" /><br />Obedient:<input name="iam[]" type="checkbox" value="obedient" /><br />Incoherent:<input name="iam[]" type="checkbox" value="incoherent" /><br />Drunk:<input name="iam[]" type="checkbox" value="drunk" /><br />Unfocused:<input name="iam[]" type="checkbox" value="unfocused" /><br />Desired:<input name="iam[]" type="checkbox" value="unfocused" /><br />Unrelenting:<input name="iam[]" type="checkbox" value="unrelenting" /><br />Full of Shit:<input name="iam[]" type="checkbox" value="fullofshit" /><br />Uncircumsized:<input name="iam[]" type="checkbox" value="uncircumsized" /><br />How would you say the following please pick only one:<br />Thank you:<input name="choice" type="radio" checked="checked" value="thankyou" /><br />Go To Hell:<input name="choice" type="radio" value="gotohell" /><br />What are you doing:<input name="choice" type="radio" value="whatareyoudoing" /><br />Now please pick out of the following, which ones apply to you:<br />Fat:<input name="decision[]" type="checkbox" value="fat" /><br />Skinny:<input name="decision[]" type="checkbox" value="skinny" /><br />Tall:<input name="decision[]" type="checkbox" value="tall" /><br />Short:<input name="decision[]" type="checkbox" value="short" /><br />Man:<input name="decision[]" type="checkbox" value="man" /><br />Woman:<input name="decision[]" type="checkbox" value="woman" /><br /><input name="submit" type="submit" value="submit me now" onsubmit="checkform()" /><input name="reset" type="reset" value="reset this and die" /></form></body></html>[/code]below is external javascript[code]function checkform() {if (document.formtest.firstname == ") {alert('Please enter a value for the First Name');} else if (document.formtest.lastname == ") {alert('Please enter a value for the Last Name');}return true;}[/code]and the problem is, it's doing nothing at all, nothing onsubmit, I know that hte onsubmit is there, but I also tried doing onsubmit="samething"at the <form> tag, and it didn't work either.[b]Problem solved/.[/b] Quote Link to comment https://forums.phpfreaks.com/topic/8593-validation-with-javascript/ Share on other sites More sharing options...
Ninjakreborn Posted April 28, 2006 Author Share Posted April 28, 2006 ok I have done a few things new to it, I moved it from the external file to the same page, I suppose I have to learn how to do it on that page, before I can run it from an external file. Now I have done some modifications, found some errors, fixed a few things as I learned, but it still doesn't seem to work, here is all the code on the same page.I tried onSubmit="" like I was showed, but it didn't work it's actually onsubmit="" without the capital S, it turned up error on w3schools validator.So here is the new code.[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>php test page</title><script language="javascript" type="text/javascript">function checkform(){ if (document.formtest.firstname.text.firstname == ""){alert('Please enter a first name!');return false;} else if (document.formtest.text.lastname == "") {alert('Please enter a last name!');return false;} return true;}</script></head><body>Please fill in the following form and submit the information to me:<br /><form name="formtest" action="formprocessor.php" method="post" onsubmit="return checkform()">First Name:<input name="firstname" type="text" maxlength="30" /><br />Last Name:<input name="lastname" type="text" maxlength="30" /><br />Age:<input name="age" type="text" maxlength="3" /><br />Please enter desired Username:<input name="username" type="text" maxlength="35" /><br />Please verify Username:<input name="verifyusername" type="text" maxlength="35" /><br />Please enter desired password:<input name="password" type="password" maxlength="25" /><br />Please verify your password:<input name="verifypassword" type="password" maxlength="25" /><br />Now for the section to tell me a little bit about yourself.<br />Please enter information about your personal life below:<br /><input name="personallife" type="text" /><br />Please enter all the programming languages you currently know:<br /><input name="languages" type="text" /><br />Please enter all your past experiences below:<br /><input name="experiences" type="text" /><br />Please check all that apply:<br />I am:<br />Perfect:<input name="iam[]" type="checkbox" value="perfect" /><br />Obedient:<input name="iam[]" type="checkbox" value="obedient" /><br />Incoherent:<input name="iam[]" type="checkbox" value="incoherent" /><br />Drunk:<input name="iam[]" type="checkbox" value="drunk" /><br />Unfocused:<input name="iam[]" type="checkbox" value="unfocused" /><br />Desired:<input name="iam[]" type="checkbox" value="unfocused" /><br />Unrelenting:<input name="iam[]" type="checkbox" value="unrelenting" /><br />Full of Shit:<input name="iam[]" type="checkbox" value="fullofshit" /><br />Uncircumsized:<input name="iam[]" type="checkbox" value="uncircumsized" /><br />How would you say the following please pick only one:<br />Thank you:<input name="choice" type="radio" checked="checked" value="thankyou" /><br />Go To Hell:<input name="choice" type="radio" value="gotohell" /><br />What are you doing:<input name="choice" type="radio" value="whatareyoudoing" /><br />Now please pick out of the following, which ones apply to you:<br />Fat:<input name="decision[]" type="checkbox" value="fat" /><br />Skinny:<input name="decision[]" type="checkbox" value="skinny" /><br />Tall:<input name="decision[]" type="checkbox" value="tall" /><br />Short:<input name="decision[]" type="checkbox" value="short" /><br />Man:<input name="decision[]" type="checkbox" value="man" /><br />Woman:<input name="decision[]" type="checkbox" value="woman" /><br /><input name="submit" type="submit" value="submit me now" /><input name="reset" type="reset" value="reset this and die" /></form></body></html>[/code]and it's still not working. Quote Link to comment https://forums.phpfreaks.com/topic/8593-validation-with-javascript/#findComment-31515 Share on other sites More sharing options...
Ninjakreborn Posted April 28, 2006 Author Share Posted April 28, 2006 bump Quote Link to comment https://forums.phpfreaks.com/topic/8593-validation-with-javascript/#findComment-31553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.