I want to know why I'm getting the error "uncaught referenceerror invalid left-hand side in assignment" in scripts.js: line 3 Ok, so the requirements of the form are as follows: First name and Last name should only contain letters. The form validation shall check the Firstname and Lastname fields, if they equal the defined name and the school is equal to the defined school then you should display the requested logo on the form page and change the page background color to green. The form validation shall ensure that the email addresses entered by the user match and are valid email addresses. If they do not match you should show the user an error message and put the focus (this is a form property!) on that field so the user can correct their error. The form validation shall return focus to incorrectly completed form fields (or the first incorrect if there are more than one incorrectly complete fields). The form validation shall give the user feedback that their form has been completed incorrectly by giving the user an error message. The form validation shall change the background color of incorrectly completed fields to red. Here's the HTML Form: <form method="post" id="myForm" name="input"> First name: <input type="text" id="fName" ></br> Last name: <input type="text" id="lName" ></br> Email: <input type="text" id="emailAddress" ></br> Repeat Email: <input type="text" id="emailAddress1" ></br> Phone Number: <input type="text" id="pNumber" ></br> <select> <option value="" disabled="disabled" selected="selected">Please select your school</option> <option value="1">Binghamton University</option> <option value="2">MIT</option> <option value="3">Harvard</option> <option value="4">Berkley</option> </select> </br> <input type="submit" onClick = "validate_form()"> </form> HTML: Here's my Javascript code function validate_form(){ if(document.getElementById('fName').value == "" += validName() = false){ document.getElementById('fName').style.background-color = 'red'; alert("First name must be filled out"); return false; } else if(document.getElementById('lName').value == "" += validName() = false){ document.getElementById('lName').style.background-color = 'red'; alert("Last name must be filled out"); return false; } else if(document.getElementById('pNumber').value == ""){ document.getElementById('pNumber').style.background-color = 'red'; alert("Phone Number name must be filled out"); return false; } else if(document.getElementById('emailAddress').value == "" += validEmail() = false){ document.getElementById('emailAddress').style.background-color = 'red'; alert("Email must be filled out"); return false; } else if(document.getElementById('emailAddress1').value == "" += validEmail() = false){ document.getElementById('emaildAddress1').style.background-color = 'red'; alert("First name must be filled out"); return false; } else{ changePage(); } return false; } function changePage(){ var firstName = "Martin" var lastName = "Neuhard" var theSchool = "Binghamton University" if(document.getElementById('fName').value == firstName += document.getElementById('lName').value == lastName += document.getElementById('schoolName').value == theSchool){ document.getElementById('content').style.background-color = 'green'; document.getElementById('content').style.background-image = 'url(http://www.heritage-flag.com/binghamton-university-bearcats/cats.gif)'; return true; } else if(changePage() = true){ } } function validName(){ var str = document.getElementById('fName').value; var reg = new RegExp("[^a-zA-Z]"); if (reg.test(str)){ return false; } else{ return true; } } Code (markup):
Your if statements are gibberish and trying too hard. you can't += after a == At least not without a lot more (). Not sure what you're trying to do there but I think you're not automating the checks enough... though the incomplete form with missing attributes and tags certainly can't be helping. NOT that ANY of this is something I'd be doing client-side in the first place. Remember, make the page work WITHOUT scripting before you even THINK about enhancing it further.
Looking at your code more, do you mean && instead of += ??? Not that there's any reason to = false, which I suspect you meant == Gah, what the devil are you trying to do there?
It's ok, I ended up getting everything to work. I've never worked with JS before I'm more of a VBA guy so the syntax was all screwed up.
That explains a lot. I jump between languages a good deal too -- it's a pain when doing AT&T style and Intel style ASM side-by-side, with src,dest vs. dest,src ... or switching back and forth between php and js where I keep trying to use periods for string addition in js or + for string addition in PHP Really can drive you nutters after a while -- the minor syntax differences.