6 Replies - 1283 Views - Last Post: 21 June 2013 - 11:34 PM

#1 patk570  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 13-February 13

JS Form Validation not working.

Posted 21 June 2013 - 07:54 PM

I am working on this form, and for some reason it is not working at all, it will not validate the fields.

Any suggestions why?


Here is my code for the JS:

<script type="text/javascript">
function checkform()
{
	if (document.form4.name.value == '') {
		alert('Full name is required');
	return false;
	}
	else if (!document.form4.password[0].checked &&
!document.form4.password[1].checked {
	alert('Please specify if there is a password');
	return false;
	}
	else if (document.form4.address.value==''){
		alert('Address cannot be blank');
	return false;
	}
	else if (document.form4.phone.value==''){
		alert('Phone field cannot be blank');
	return false;
	}
	else if (document.form4.email.value==''){
		alert('Email cannot be blank');
		return false;
	}
	else if (document.form4.passwordYes.value=='Put password here'){
		alert ('Please put your password in the box');
		return false;
	}
	return true;
}
</script>



Here here is my form:

		<form method="post" name="form4"  onsubmit="return checkform()" action="#">
        <table width="100%" cellpadding="5" cellspacing="5" id="ticketForm">
        <tr>
          <td>Full Name</td><td><input type="text" name="name" /></td></tr>
        <tr><td>Address</td><td><textarea cols="50" name="address"></textarea></td></tr>
        <tr><td>Phone Number</td><td><input type="text" id="phone" name="phone" onfocus="if(this.value==this.defaultValue)this.value='';" maxlength="14" onclick="javascript:getIt(this)" /></td></tr>
        <tr><td>Email Address</td><td><input type="text" name="email" /></td></tr>
        <tr>
          <td>Is there a password on your computer?</td>
          <td><input onclick="toggle_visibility('passwordYes');" type="radio" checked="checked" name="password" value="yes" />
          Yes<input type="radio" onclick="toggle_visibility('passwordYes');" value="no" name="password" />
          No<input value="Put password here" style="display:block;" onclick="this.value='';" type="text" name="passwordYes" id="passwordYes" /></td></tr>
          <tr>
            <td>How did you find us?</td>
            <td><textarea cols="50"  name="referredby"></textarea></td></tr>
            <tr><td colspan="2" align="right"><input type="submit" value="Submit" /></td></tr>
        </table>
      </form>



Thanks in advance,

P.

Is This A Good Question/Topic? 0
  • +

Replies To: JS Form Validation not working.

#2 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: JS Form Validation not working.

Posted 21 June 2013 - 08:56 PM

What does the console say? I see that there is an error at the && on line 8 of your JS code.
Was This Post Helpful? 0
  • +
  • -

#3 patk570  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 13-February 13

Re: JS Form Validation not working.

Posted 21 June 2013 - 09:01 PM

I was actually coming back to get it updated, I forgot a damn parenthesis at the end of that code string. I feel so damn stupid and i look at it like 35 times...UGH...Maybe late night coding is a bad idea..

Thanks,

laytonsdadfor your reply!
Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: JS Form Validation not working.

Posted 21 June 2013 - 09:08 PM

I was just getting ready to reply this as an edit when I seen your post.
Was This Post Helpful? 0
  • +
  • -

#5 patk570  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 13-February 13

Re: JS Form Validation not working.

Posted 21 June 2013 - 09:10 PM

SUCH an idiot I am lol...
Was This Post Helpful? 0
  • +
  • -

#6 codespook  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 31-October 12

Re: JS Form Validation not working.

Posted 21 June 2013 - 11:04 PM

View Postpatk570, on 21 June 2013 - 09:10 PM, said:

SUCH an idiot I am lol...


Late night coding has its pros and cons.

Actually I thought every form should have a seperate if statement. So I guess I learned something new. One person's headache is another's bonus:-)
Was This Post Helpful? 0
  • +
  • -

#7 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: JS Form Validation not working.

Posted 21 June 2013 - 11:34 PM

View Postcodespook, on 22 June 2013 - 06:04 AM, said:

Actually I thought every form should have a seperate if statement.

I think that this page may help you with logical operators, take a look it can't hurt. :cowboy:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1