Jump to content

OnBlur & OnKeyPress Doesn't work.


Mudsaf

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...