0

Hi I am new to java script im developing a web application where i need to check Username availability on the client side that is when the user inputs his desired Username it should check from MySql database login table and update the status available or not available. I tried searching over the net but i found only Ajax code. I need it in Java script so some one help me in this regard.

This is my Username JSP for your reference..

<tr>
    <td> UserName* :</td>
    <td>
        <input type="text" name="Username" id="username"/><br/>
       </td>
</tr>
2
  • 2
    can't possible untill you loads all username in javascript Commented Feb 26, 2014 at 6:02
  • @Govind Singh Nagarkoti can u elaborate your sentence more clearly. Commented Feb 26, 2014 at 6:27

4 Answers 4

0

you can do it with jquery in your jsp something like this:

<tr>
<td>Choose your UserName* :</td>
<td><script type="text/javascript" src="jquery.js"></script>
<input type="text" name="txtUsername" id="username">@gmail.com
<div id="status"></div>
<script type="text/javascript" src="js/check_user.js"></script>
<span id="errorMissingUserName" style="display:none;"><font color="red">*Please provide your username.</font></span>
<span id="errorUserNameInvalid" style="display:none;"><font color="red">*Please provide a valid username.Username can contain only alphabets numbers and periods</font></span>
<span class="status"></span>
</tr>

go through this [link][ check user name avialability using jsp and mysql... There is a little problem with the servlet jdbc i think if you resolve it will be k try it....

Sign up to request clarification or add additional context in comments.

Comments

0

What you want to do can't be done out of the box and could be very insecure.
Please have a look to this link: can I fetch record from mysql using jquery.
Another link: tutorials jquery and mysql.

1 Comment

its unsafe?? but i need it in my app so how to do it in a secured way?? can we use Springs like service layer and dao for this??
0

you want security, you want do in javascript, both thing cant be happen.

its better to ajax calling for availability of username
<input type="text" name="txtUsername" id="userName"/>@gmail.com<br/>

OR

sends the all usernames which are occupied by other users on the page. then use it, pass them to javascript and store them an array. and then checks availability(not recommended because its not safe).

ajax is 100 times secure then storing in javascript

1 Comment

but i dono ajax can u pls help me
0

Clarifying what Govind is saying here. To check the availability of usernames client side would require having all the usernames client side.

Also, even if you do implement an ajax solution, you need to be mindful that you are still exposing your usernames to anyone willing to write a loop.

Easiest somewhat secure solution is to rate limit the responses for username validation, and use jQuery form validation for your test.

Don't fear the ajax. It is simply a GET request to a url you expose server side, which returns the string true/false. The form validation plugin takes care of making the request and doing what you want on pass/fail.

$( "#myform" ).validate({
  rules: {
    email: {
      required: true,
      email: true,
      remote: "check-email.php"
    }
  }
});

jQuery makes the ajax validation easy.

Related question with code. (php, but you'll get it.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.