Jump to content


This topic is now archived and is closed to further replies.


Basic Form Help on script and a question related to JS Validation RESOLVED

Recommended Posts

Hi All

I 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." );
    return false ;
  return true ;
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 help


Share this post

Link to post
Share on other sites
May be:

<form name="form" action="upload2.php" method="POST" onsubmit="return checkForm([color=red]this[/color])">

try it .

Share this post

Link to post
Share on other sites
I made the change and still have the same problem. :(  Any other ideas?

Share this post

Link to post
Share on other sites
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);"

Share this post

Link to post
Share on other sites
That solved the problem.  Thank You very much for the help.  Now, I can quit being so frustrated.


Share this post

Link to post
Share on other sites


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.