Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 10 July 2006 - 08:01 PM

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.

<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>

and then I have this added in the <body> at the start of the form.

<form name="form" action="upload2.php" method="POST" onsubmit="return checkForm()">

The button is configured to be a submit button

<input type="submit" name="Submit" value="Add Item" />


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

Ken

#2 wakmp

wakmp
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 July 2006 - 02:08 AM

May be:

<form name="form" action="upload2.php" method="POST" onsubmit="return checkForm(this)">

try it .

#3 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 11 July 2006 - 03:33 AM

I made the change and still have the same problem. :(  Any other ideas?

#4 wakmp

wakmp
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 July 2006 - 05:17 AM

onsubmit="return checkForm(this);"

I think you should use lowercase :

onsubmit="return checkform(this);"



#5 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 11 July 2006 - 05:48 AM

That solved the problem.  Thank You very much for the help.  Now, I can quit being so frustrated.

ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users