Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2011
    Location
    Romania
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    jQuery script not working

    I have this HTML code:

    PHP Code:
    <form method="post" action="register.php">
            <
    table style="margin-top:30px;" cellpadding="3">
            <
    tr><td><strong>Username(<color="red">*</color>):</strong></td><td><input type="text" id="usernameinput" size="30" class="forms" onBlur="user()"><p id="usernamep"></p></td></tr>
            <
    tr><td><strong>Nume complet:</strong></td><td><input type="text" id="nume" size="30" class="forms"><p id="nume"></p></td></tr>
            <
    tr><td><strong>Password(<color="red">*</color>):</strong></td><td><input type="password" id="pass" size="30" class="forms"><p id="pass"></p></td></tr>
            <
    tr><td><strong>Re-type password(<color="red">*</color>):</strong></td><td><input type="password" id="repass" size="30" class="forms"><p id="repass"></p></td></tr>
            <
    tr><td><strong>E-mail(<color="red">*</color>):</strong></td><td><input type="text" id="mail" size="30" class="forms"><p id="mail"></p></td></tr>
            <
    tr><td><strong>Doriti ca e-mailul sa fie ascuns?<strong></td><td><input type="checkbox" id="hidemail"></td></tr>
            <
    br>
            <
    tr><td><input type="submit" value="Inregistreaza-te!" style="margin-left:135px;"></td></tr>
            </
    table>
        </
    form
    Then I got this .js :

    Code:
    $(document).ready(function user(){
      $("#usernameinput").blur(function(){
    	x=getElementById("usernameinput");
    	if(x.length<5)
    		$("#usernamep").html("<color=\"red\">Usernameul trebuie sa contina minim 5 caractere.</color>");
    	else if(x.length>20)
    		$("#usernamep").html("<color=\"red\">Usernameul trebuie sa contina maxim 20 de caractere.</color>");
      });
    });
    Could you please explain me what and why it's wrong?


    And also, while I'm on the topic, how can I check the mySQL database with jQuery so that I can tell the user(in the register form) whether the username is taken or not.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    1. It is document.getElementById and not just getElementById
    2. You are using jQuery, so forget about document.getElementById ... and get used to jQuery selectors
    Code:
    $('#usernameinput')
    Inside the blur method you can even use $(this)

  • Users who have thanked devnull69 for this post:

    tsuby (07-23-2011)

  • #3
    New Coder
    Join Date
    Jul 2011
    Location
    Romania
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks. The main problem of this was that I had included the header that contained the link to the google link that hosts jQuery after I made the link to the actual script. I didn't really know that would be a problem.
    Thank you.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    sine when is <color> an element??


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •