Mudsaf Posted February 28, 2012 Share Posted February 28, 2012 Somehow my form doesn't do this everytime on keypress or onblur var one = 0; <!-- Username -->var two = 0; <!-- Email -->var three = 0; <!-- Password -->var four = 0; <!-- Rules --> function check() { <!-- Starts function check() -->if (one == 0 || two == 0 || three == 0 || four == 0) { <!-- If some number is zero submit button is disabled -->document.getElementById("submit").disabled = true; <!-- Disables the submit button -->} else { <!-- Else numbers are other than 0 -->document.getElementById("submit").disabled = false; <!-- Submit button is enabled.} <!-- Closes the submit button enabler / disabler --> alert("ABC"); } Somehow it works on body onload, but not on other methods <body onload="check();"><?php include 'file/header.php'; ?><?php include 'file/list.php'; ?><div id="content"> <center><h2>Rekisteröidy Mudsaf.info:n elokuvasivuille</h2><form id="register" name="register" method="post" action="register_confirm.php"> <p><label for="username">Käyttäjänimi:</label><input name="username" type="text" id="username" maxlength="20" onKeyPress="check();" onBlur="check();"> <label for="password">Salasana:</label> <input type="password" maxlength="30" name="password" onblur="check();" id="password" /> <label for="email">Sähköpostiosoite:</label> <input type="text" name="email" maxlength="100" onblur="check();" id="email" /> <input type="submit" name="submit" id="submit" value="Lähetä" /><p> <strong>Säännöt</strong></p><input type="checkbox" name="check" id="check" onblur="check();"/><label for="check">Hyväksyn sivuston säännöt ja noudatan niitä.</label><p> <textarea name="rules" cols="70" draggable="false" disabled="disabled" rows="5" readonly="readonly" id="rules">LARGE AMOUT OF TEXT HERE</textarea></p> <p>Ennen kuin voit rekisteröityä sivuille sinun täytyy hyväksyä ylläolevat säännöt.</p></form> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 28, 2012 Share Posted February 28, 2012 First, remove the HTML comments in the Javascript code. Use Javascript comments if you want comments there. Also, keep an eye on the browser's error console to look for Javascript errors. I don't see any code that changes the values of the four variables you're checking. Either you decided that wasn't important to see or you left that out of your code. Link to comment Share on other sites More sharing options...
Mudsaf Posted February 28, 2012 Author Share Posted February 28, 2012 Nothing had to change the codes yed, i was trying to get the alert work after blur from form element comments changed, still no effect. var one = 0; // Usernamevar two = 0; // Emailvar three = 0; // Passwordvar four = 0; // Rulesfunction check() { // Starts function check()if (one == 0 || two == 0 || three == 0 || four == 0) { // If some number is zero submit button is disableddocument.getElementById("submit").disabled = true; // Disables the submit button} else { // Else numbers are other than 0document.getElementById("submit").disabled = false; // Submit button is enabled.} // Closes the submit button enabler / disabler alert("ABC"); } Link to comment Share on other sites More sharing options...
Mudsaf Posted February 28, 2012 Author Share Posted February 28, 2012 On error log it says check() is not function error on line 1 O_o Link to comment Share on other sites More sharing options...
justsomeguy Posted February 28, 2012 Share Posted February 28, 2012 At what point does that error message appear? How is the script linked to that HTML page? Does the alert still show on load? Link to comment Share on other sites More sharing options...
Mudsaf Posted February 28, 2012 Author Share Posted February 28, 2012 Alert shows on load, but not on blur or on key press. Javascript linked like this: <script type="text/javascript" src="js/lockon.js"></script> Link to comment Share on other sites More sharing options...
thescientist Posted February 28, 2012 Share Posted February 28, 2012 http://www.w3schools.com/jsref/event_onkeypress.asphttp://www.w3schools.com/jsref/event_onblur.asp onkeypressonblur Link to comment Share on other sites More sharing options...
Mudsaf Posted February 28, 2012 Author Share Posted February 28, 2012 Well its strange because of this works and not the mine 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script type="text/javascript">function test() {alert ("ABC");}</script></head><body><label for="test"></label><input type="text" name="test" onkeypress="test();" id="test" /></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 28, 2012 Share Posted February 28, 2012 If it says that check is not a function then there is either a problem linking the file, or there is a syntax error in the Javascript, or you are trying to execute the function before it was defined, like if you link to the Javascript file at the end of the body. Link to comment Share on other sites More sharing options...
Mudsaf Posted February 28, 2012 Author Share Posted February 28, 2012 Fixed when chanaged check() to correctcheck() O_O Link to comment Share on other sites More sharing options...
justsomeguy Posted February 28, 2012 Share Posted February 28, 2012 That's interesting, I thought that it may be possible that check would be a reserved word or predefined, but I didn't get any results searching for window.check. This list also does not say that check is reserved: http://www.perlscriptsjavascripts.com/tutorials/javascript/keywords_1.html Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.