Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  150] [ 2]  / answers: 1 / hits: 20644  / 14 Years ago, sat, february 19, 2011, 12:00:00

I require the username used by the user in my project be compared to other usernames already registered. The username should be distinct. For this the input is taken in newuser.jsp which in turn calls a function searchForUsername in SemanticSearch.java. When the new user is registering even the email id is checked for validation and later when the username is typed the above checking needs to be done.
I have tried one way which is not working.Please point what mistake I am doing?



My code in SemanticSearch.java has constructor:



public SemanticSearch() {}


The following code follows after validation of email id.



My code in newuser.jsp is



SemanticSearch myclass=new SemanticSearch();

boolean rets=myclass.searchForUsername(username);

if (rets==false)

{

alert(Username already exists);

document.getElementById(username).value=;

document.getElementById(password).value=;

document.getElementById(username).focus();

}


During the click event of adduser button this function has to be called. But during the click function nothing seems to happen. Please help.


More From » java

 Answers
1
<%
SemanticSearch myclass=new SemanticSearch();

boolean rets=myclass.searchForUsername(username); // how do you get username on button click and assign it to this variable?

if (rets==false)
{
%>


I guess you can assign a Java variable to a JavaScript variable



var username = '<%= username%>';


but does the vice versa work?



<%String username = %>document.getElementById(username).value<%:%>


I would prefer BalusC's approach (1st one), a javascript validation for this case can be risky as mostly all the browsers support disabling of javascript.


[#93670] Thursday, February 17, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raveno

Total Points: 453
Total Questions: 92
Total Answers: 92

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
raveno questions
;