kenwvs Posted July 10, 2006 Share Posted July 10, 2006 Hi AllI have never used a form validation (except for FP) and am trying to stay away from FP and learn how to do things.I have a form that has 16 fields to fill in. Some are required, and some are not. At the moment, to try my script out, I have only made the User ID a required field. My understanding is if this field is left blank, it would result in a pop up saying "Please enter a valid User Name" (this name could be anything in this case).For some reason, if I leave the field blank, it proceeds as if nothing is wrong. I have borrowed this script from a help site, and have changed it for my names, etc. Was I correct in reading that the script should be placed in the <HEAD> portion of the page and not in the <BODY>? Here is the script I am using. When I get this field to work properly, I will add the additional lines for each of the other required fields. When you press submit it takes you to a confirmation page, which is PHP and allows you to make a choice as to what you want to do next and where you want to go.[quote]<script language="JavaScript" type="text/javascript"><!--function checkform ( form ){if (form.id.value == "") { alert( "Please enter a valid User ID." ); form.id.focus(); return false ; } return true ;}//--></script>[/quote]and then I have this added in the <body> at the start of the form.[quote]<form name="form" action="upload2.php" method="POST" onsubmit="return checkForm()">[/quote]The button is configured to be a submit button[quote]<input type="submit" name="Submit" value="Add Item" />[/quote]On this line (form.id.value == "") am I correct in reading this that it basically says it the input field is blank (""), nothing in here, then return it false? If I wanted it to be anything but the number 123, could I put 123 in there and it would return false, only if 123 was entered?Thanks for the helpKen Quote Link to comment https://forums.phpfreaks.com/topic/14219-basic-form-help-on-script-and-a-question-related-to-js-validation-resolved/ Share on other sites More sharing options...
wakmp Posted July 11, 2006 Share Posted July 11, 2006 May be:<form name="form" action="upload2.php" method="POST" onsubmit="return checkForm([color=red]this[/color])">try it . Quote Link to comment https://forums.phpfreaks.com/topic/14219-basic-form-help-on-script-and-a-question-related-to-js-validation-resolved/#findComment-55952 Share on other sites More sharing options...
kenwvs Posted July 11, 2006 Author Share Posted July 11, 2006 I made the change and still have the same problem. :( Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/14219-basic-form-help-on-script-and-a-question-related-to-js-validation-resolved/#findComment-55984 Share on other sites More sharing options...
wakmp Posted July 11, 2006 Share Posted July 11, 2006 onsubmit="return check[color=red][u]F[/u][/color]orm(this);"I think you should use lowercase :onsubmit="return check[color=green][u]f[/u][/color]orm(this);" Quote Link to comment https://forums.phpfreaks.com/topic/14219-basic-form-help-on-script-and-a-question-related-to-js-validation-resolved/#findComment-56027 Share on other sites More sharing options...
kenwvs Posted July 11, 2006 Author Share Posted July 11, 2006 That solved the problem. Thank You very much for the help. Now, I can quit being so frustrated.ken Quote Link to comment https://forums.phpfreaks.com/topic/14219-basic-form-help-on-script-and-a-question-related-to-js-validation-resolved/#findComment-56035 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.