This part of the fine (I allowed to correct the indentation):
function checknewaccount(){ if(emailvalid()&& checkname() && passwordcheck()) { return true; } else{ return false; } }
Although you can improve it:
function checknewaccount(){ return emailvalid() && checkname() && passwordcheck(); }
This part is a syntax error (to put it mildly):
function emailvalid(), checkname(), passwordcheck(){ if(condition){ return true;} else{return false;}
If this is not a real quote from your code, you will have to update your question (although I may not be here to update this answer). It doesn't make much sense to ask about the code, and then quote the pseudocode in the question. (At least the pseudocode is missing the final one. } )
The same is true for your functions in the form:
function emailvalid() { if(email condition) { return true; } else { return false; } }
This is fine (assuming email condition is still psuedocode), but there is no need for if :
function emailvalid() { return email condition; }
In terms of “nothing happens” make sure you have debugging tools that you can use. Chrome has Dev built-in tools, just press Ctrl + Shift + I. For Firefox you can install a great Firebug. Recent IE versions have built-in dev tools (for older versions, you can download the free version of Visual Studio, which can connect to the browser). Any of them will tell you about the syntax and other errors, let you go through your code line by line, etc., which is crucial for figuring out what is happening.
Here's a quick-dropped version of what I think you're trying to do. I would not do it this way, but I made minimal changes to make it work:
HTML:
<form action="http://www.google.com/search" method="GET" target="_blank" onsubmit="return checknewaccount()"> <input type="text" id="email" name='q' onblur="emailvalid()"> <input type="text" id="username" onblur="checkname()" > <input type="password" id="password" onkeyup="passwordcheck()"> <input type="submit" value="New"> </form>
Notes to this:
- As pointed out in Basiclife , your
form code has problems. They are fixed above. - I used
action="http://www.google.com/search" above, but of course it will be action="accountcode.php" for you (or at least I think it will). - Use
onsubmit for the form submission handler, not the onclick on the submit button. You cannot cancel submitting a form with a reliable cross-browser through the onclick submit button. - In
onsubmit make sure you use return - for example, onsubmit="return checknewaccount()" , and not onsubmit="checknewaccount()" - because we want to make sure that the event material sees the return value. We don’t care if the event material does not see the return value of our other checks ( onblur="emailvalid()" ), but if we did, we need return . - Only one of the fields above has a
name attribute; none of you do. Only fields with name attributes are passed with forms. I used only one name for my example because I want to send only one field to Google, but for your purposes you will need the name attribute for all three fields. This short article discusses id vs. name and what they are for. You sometimes need both. - I put the attributes in all downstream ones, which is best (and required if you want to use XHTML).
- However, I removed
/ from the ends of the inputs . This is a little off topic, but at the apparent level that you are working on, you do not want to try to use XHTML, use HTML. Using XHTML correctly is technically difficult, both in authoring configuration and in server configuration, and even then you should serve it as a soup tag for IE or it will not process it properly. XHTML has its place, but in the vast majority of cases there is no reason to use it. - In the above combination with the JavaScript below, there is no purpose for handlers in separate fields. However, I left them because I assume that you are doing more than just the checks below - there is another example showing that these handlers are doing something useful.
JavaScript:
function checknewaccount() { return emailvalid() && checkname() && passwordcheck(); } function emailvalid() { var element;
Live copy
Things change a bit if emailvalid , et. al., the functions are going to do something so that the user knows that the fields are invalid, for example, highlighting their labels:
HTML:
<form action="http://www.google.com/search" method="GET" target="_blank" onsubmit="return checknewaccount()"> <label>Email: <input type="text" id="email" name='q' onblur="emailvalid()"></label> <br><label>Username: <input type="text" id="username" onblur="checkname()" ></label> <br><label>Password: <input type="password" id="password" onkeyup="passwordcheck()"/></label> <br><input type="submit" value="New"> </form>
JavaScript:
function checknewaccount() { var result;
Live copy