Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append domain to UserID input type

Status
Not open for further replies.
Oct 17, 2003
5
US
Hi all. I know very little about JS, but I'm looking to add to this code that sets the cursor focus on my login form. I would like to append a domain (e.g. @company.com) to the "loginname" form field after the focus changes to the "password" form field. Can anyone help please?

<!--

if (document.login.loginname.value == &quot;&quot;) {
document.login.loginname.focus()
} else {
document.login.password.focus()
}

function focuspwd()
{
document.login.password.focus();
return(true);
}

function focusloginbutton()
{
document.login.loginbutton.focus();
return (true);
}

//-->
 
like so?

<!--

if (document.login.loginname.value == &quot;&quot;) {
document.login.loginname.focus()
} else {
if (document.login.loginname.indexOf(&quot;@company.com&quot;) == -1) {
document.login.loginname += &quot;@company.com&quot;;
}
document.login.password.focus()
}

function focuspwd()
{
document.login.password.focus();
return(true);
}

function focusloginbutton()
{
document.login.loginbutton.focus();
return (true);
}

//-->


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Add to the loginname input tag onblur:

Example:

<input id=&quot;loginname&quot; type=&quot;textbox&quot; onblur=&quot;CheckAdd()&quot;>

The JS Function

function CheckAdd(){
//replace with whatever domain you want to use
var sAppendDomain=&quot;@Company.com&quot;;

//get Login input object
var objLoginName=document.getElementById(&quot;loginname&quot;);

//Check to see if already appended
if (parseInt(objLoginName.value.indexOf(sAppendDomain))==-1){
//append the domain
objLoginName.value=objLoginName.value+sAppendDomain;
}

}

MrGreed

&quot;did you just say Minkey?, yes that's what I said.&quot;
 
Thanks Jeff. Now, how do I set the &quot;UserID&quot; input to go to the correct function after the focus changes? Here is what I have now for the input:

<input type=&quot;text&quot; name=&quot;UserID&quot; size=&quot;20&quot; onchange=&quot;focuspwd()&quot;

Sorry if I wasn't specific enough in the original post...

Thanks.
Stephen
 
if you're going to call focuspwd() onchange, then i would do it this way:

<!--
function focuspwd() {
if (document.login.loginname.indexOf(&quot;@company.com&quot;) == -1) {
document.login.loginname += &quot;@company.com&quot;;
}
document.login.password.focus();
return true;
}

function focusloginbutton() {
document.login.loginbutton.focus();
return true;
}
//-->

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Jeff / Mr. Greed,

Brilliant! Actually used a combination of the two and it works perfectly. Many thanks.

Stephen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top