Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-22-2011, 05:23 PM   PM User | #1
tsuby
New to the CF scene

 
Join Date: Jul 2011
Location: Romania
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
tsuby is an unknown quantity at this point
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.
tsuby is offline   Reply With Quote
Old 07-22-2011, 07:13 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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)
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
tsuby (07-23-2011)
Old 07-23-2011, 09:56 AM   PM User | #3
tsuby
New to the CF scene

 
Join Date: Jul 2011
Location: Romania
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
tsuby is an unknown quantity at this point
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.
tsuby is offline   Reply With Quote
Old 07-23-2011, 12:11 PM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
sine when is <color> an element??
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:14 AM.


Advertisement
Log in to turn off these ads.