Hi,
I am working on a project in which there are two textbox one for user id and other for password.
The requirement is that if user enter incorrect user id on that case
focus goes to user id text field and if user enters correct user id and
wrong password in that case it should show focus on password box.
i have written the below code:
if(objXMLHttp_Login.responseXML.getElementsByTagName(string)[0].childNodes[0].nodeValue == 2)
{
alert(Incorrect E-mail address, user does not exist.);
document.all(txt_username).focus();
document.getElementById(txt_password).value="";
document.getElementById(txt_username).value="";
document.getElementById(div_pre_login).style.display = '';
}
else if(objXMLHttp_Login.responseXML.getElementsByTagName(string)[0].childNodes[0].nodeValue == 0)
{
alert(Incorrect Password.);
document.getElementById(div_pre_login).style.display = '';
document.all.item('txt_password').focus();
document.getElementById(txt_password).value="";
}
Thanks & Regards
Vinay Singh
Loading

Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 9, 2009, 9:14 PM EST
You can set the focus using following code.
document.getElementById(txt_password).focus()
For the username also u can use the same way.
If this helps please accept my answer.
Posted Nov 9, 2009, 9:20 PM EST
As u said user .focus();
but it's not working. it's giving error
.focus is not a method.
Regards
vinay
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 9, 2009, 10:20 PM EST
document.formname.elements[ i ].focus()
Here i is the index of the control.
Sriram Ramani144 reputationPosted Nov 9, 2009, 10:40 PM EST