user1203861
user1203861

Reputation: 1217

Javascript form validation failing

i am trying to validate a form with java script .. yet the javascript does not output anything and the form completes into processing.

here is the script tag:

here is the form tag:

<FORM  id="frm" name="newCustomer" METHOD="POST" ACTION="register.php" onsubmit="return      validateNewCustomer()">

i've created this label so that java script can write the warnings:

  <TH WIDTH="30%" NOWRAP> <Label>First Name</Label></TH>
      <TD WIDTH="70%"><INPUT TYPE="TEXT" NAME="f_name" 
                             SIZE="8" MAXLENGTH="8">
         <label class ="err" id="errname"></label>

Here is the valdiation function :

  function validateNewCustomer(){

var name = document.getElementById('f_name').value;
var okCustomer = true;

if(name == ""){
document.getElementById('errname').innerHTML = "Error Name";
okCustomer = okCustomer && false;
}

return okCustomer;

}

I should note that i tried to make the function return false , but it still didn't stop php processing.

I appreciate your help.

Thank you.

Upvotes: 0

Views: 142

Answers (3)

Sethunath K M
Sethunath K M

Reputation: 4761

Use

if(name.value == ""){

instead of

if(name == ""){

Upvotes: 0

Bibin Velayudhan
Bibin Velayudhan

Reputation: 3103

Your code is wrong use

var name = document.getElementsByName('f_name').value;

instead of

var name = document.getElementsById('f_name')[0].value;

Upvotes: 0

mgraph
mgraph

Reputation: 15338

var name = document.getElementByName('f_name').value;

and

okCustomer = false; instead of okCustomer = okCustomer && false;

Upvotes: 1

Related Questions