wait maybe i missread
Do you want it to do the same thing as the link you posted?
Main Topics
Browse All TopicsThe title says it all I guess. I am not a JS guru. I am looking for a javascript script that would add the domain after the user name same as Hotmail does on their site. I am trying to modify the SquirrelMail webmail application's /src/login.php file so that a designated @domain.com can be inserted after user types his ID and moves to the password field. This is a requirement of the site's login process. The site is unique and the @... is specific and static, but if anyone can invent something better such as pulling the domain info from the address URL, that's great too.
Since the page has PHP, it may also be easier to add some PHP tags there, but I think JS would be the easiest way to go. If you want to see how Hotmail script works, look at the source in their login page.
Any working solution or workaround would help.
Since I have seen JS scripts implement similar to this with as little as 5 lines, I don't think this will be a majot effort. A similar sample is at http://www.mybannertaxi.co
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
this is the complete login.php file contents:
<?php
/**
* login.php -- simple login screen
*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This a simple login screen. Some housekeeping is done to clean
* cookies and find language.
*
* $Id: login.php,v 1.98.2.1 2003/07/03 20:24:47 stekkel Exp $
*/
/* Path for SquirrelMail required files. */
define('SM_PATH','../');
/* SquirrelMail required files. */
require_once(SM_PATH . 'functions/strings.php');
require_once(SM_PATH . 'config/config.php');
require_once(SM_PATH . 'functions/i18n.php');
require_once(SM_PATH . 'functions/plugin.php');
require_once(SM_PATH . 'functions/constants.php')
require_once(SM_PATH . 'functions/page_header.php
require_once(SM_PATH . 'functions/html.php');
require_once(SM_PATH . 'functions/global.php');
/*
* $squirrelmail_language is set by a cookie when the user selects
* language and logs out
*/
set_up_language($squirrelm
/**
* Find out the base URI to set cookies.
*/
if (!function_exists('sqm_bas
require_once(SM_PATH . 'functions/display_message
}
$base_uri = sqm_baseuri();
/*
* In case the last session was not terminated properly, make sure
* we get a new one.
*/
sqsession_destroy();
header('Pragma: no-cache');
do_hook('login_cookie');
/* Output the javascript onload function. */
$header = "<script language=\"JavaScript\" type=\"text/javascript\">\
"<!--\n".
" function squirrelmail_loginpage_onl
" document.forms[0].js_autod
" var textElements = 0;\n".
" for (i = 0; i < document.forms[0].elements
" if (document.forms[0].element
" textElements++;\n".
" if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
" document.forms[0].elements
" break;\n".
" }\n".
" }\n".
" }\n".
" }\n".
"// -->\n".
"</script>\n";
$custom_css = 'none';
displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
echo '<body text="#000000" bgcolor="#FFFFFF" link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="squirrelmail_login
"\n" . '<form action="redirect.php" method="post">' . "\n";
$username_form_name = 'login_username';
$password_form_name = 'secretkey';
do_hook('login_top');
$loginname_value = (sqGetGlobalVar('loginname
/* If they don't have a logo, don't bother.. */
if (isset($org_logo) && $org_logo) {
/* Display width and height like good little people */
$width_and_height = '';
if (isset($org_logo_width) && is_numeric($org_logo_width
$org_logo_width>0) {
$width_and_height = " width=\"$org_logo_width\""
}
if (isset($org_logo_height) && is_numeric($org_logo_heigh
$org_logo_height>0) {
$width_and_height .= " height=\"$org_logo_height\
}
}
echo html_tag( 'table',
html_tag( 'tr',
html_tag( 'td',
'<center>'.
( isset($org_logo) && $org_logo
? '<img src="' . $org_logo . '" alt="' .
sprintf(_("%s Logo"), $org_name) .'"' . $width_and_height .
' /><br />' . "\n"
: '' ).
( (isset($hide_sm_attributio
'<small>' . sprintf (_("SquirrelMail version %s"), $version) . '<br />' ."\n".
' ' . _("By the SquirrelMail Development Team") . '<br /></small>' . "\n" ) .
html_tag( 'table',
html_tag( 'tr',
html_tag( 'td',
'<b>' . sprintf (_("%s Login"), $org_name) . "</b>\n",
'center', '#DCDCDC' )
) .
html_tag( 'tr',
html_tag( 'td', "\n" .
html_tag( 'table',
html_tag( 'tr',
html_tag( 'td',
_("Name:") ,
'right', '', 'width="30%"' ) .
html_tag( 'td',
'<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" />' ,
'left', '', 'width="*"' )
) . "\n" .
html_tag( 'tr',
html_tag( 'td',
_("Password:") ,
'right', '', 'width="30%"' ) .
html_tag( 'td',
'<input type="password" name="' . $password_form_name . '" />' . "\n" .
'<input type="hidden" name="js_autodetect_result
'<input type="hidden" name="just_logged_in" value="1" />' . "\n",
'left', '', 'width="*"' )
) ,
'center', '#ffffff', 'border="0" width="100%"' ) ,
'left', '#FFFFFF' )
) .
html_tag( 'tr',
html_tag( 'td',
'<center><input type="submit" value="' . _("Login") . '" /></center>',
'left' )
),
'', '#ffffff', 'border="0" width="350"' ) . '</center>',
'center' )
) ,
'', '#ffffff', 'border="0" cellspacing="0" cellpadding="0" width="100%"' );
do_hook('login_form');
echo '</form>' . "\n";
do_hook('login_bottom');
echo "</body>\n".
"</html>\n";
?>
so, is that username that should be appended with domain?
find string:
<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" />
and append
<select name="quickhack"><option>@
than, find
><input type="submit" value="' . _("Login") . '"
replace "submit" with "button" and add
onclick="document.forms[0]
changes to login.php:
$header = "<script language=\"JavaScript\" type=\"text/javascript\">\
"<!--\n".
" function addEmail(fObj){ \n".
" fObj.value = fObj.value + "@mysite.net"; \n".
" } \n".
" function squirrelmail_loginpage_onl
...
'<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .' onChange="addEmail(this);"
'left', '', 'width="*"' )
but I get a : Parse error: parse error, unexpected '@' in ...\wwwroot\webmail\src\lo
I used \@ but that did not work. I took out @ completely, but it gave me another error for unexpected T_STRING
any input?
What you need is the onBlur javascript event handler. Use it like this:
<?php
if($_POST['submit']=="subm
echo "Username was: $_POST[username]<br>";
}
?>
<html>
<head>
<title>Add Domain Test</title>
<script type="text/javascript" language="Javascript1.2">
function addDomain(element) {
element.value = element.value + "@hotmail.com";
}
</script>
</head>
<body>
<form action="<?php echo $PHP_SELF; ?>" method="post" name="addDomainTest">
<input type="text" name="username" onBlur="javascript:addDoma
<input type="text" name="password"><br>
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>
Again, althugh both your answers are correct for simple HTML, I can not implement this in PHP. Either the @ character in @domain.net or the whole @domain.net is causing a PHP parse error.
Parse error: parse error in /home/public_html/mail/src
which is:
" function function addDomain(element) {\n". // added the custom JS line 57
" element.value = element.value + "@domain.net";\n". // in these lines line 58
" }\n". // here for domain line 59
any suggestions with PHP implementation?
I'm not sure why you are putting the javascript function into the PHP code, but if you are, you do have some parse error:
should be:
" function function addDomain(element) {\n". // added the custom JS line 57
" element.value = element.value + \"@domain.net]\";\n". // in these lines line 58
" }\n".
notice the way I have escaped the double quotes in line 58 with slashes. that is why you are getting the parse error. You need those slashes.
the code from rstorey2079 worked. the working changes are as follows:
$header = "<script language=\"JavaScript\" type=\"text/javascript\">\
"<!--\n".
" function addDomain(element) {\n".
" element.value = element.value + \"@domain.net\";\n".
" }\n".
" function squirrelmail_loginpage_onl
...
html_tag( 'td',
'<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" onChange="javascript:addDo
'left', '', 'width="*"' )
but one problem I noticed is that the script adds a @domain.net everytime I change something in the field. Example:
I type USRE and the script adds @domain.com
I type the password, but I notice that USRE should have been USER
I make the changes, but after I leave the field, now the text looks like: USER@domain.net@domain.net
One workaround would be to erase everything in the field and type USER at a blank box, but I am afraid the user may fail to realize what has happend, and can not see all the USER@domain.net@domain.net
due to the visible character limit in the field.
Anyone with a suggestion to kill that part of the script if @domain.net is already inserted, or make the script a one time use only?
Currently the script lines are inserted inside an existing javascript from the SquirrelMail author. Can I move them outside, so 2 JavaScripts exist in the page, but one has a 1 time use or die call.
Thanks for your help so far.
it worked like a charm! Thanks to everyone that contributed to this. I will award the points to rstorey2079 for the great help in JavaScript and the final working code, even thought it was not embedded in PHP. I figured that part out.
final code for the new SquirrelMail /scr/login.php is as follows:
$header = "<script language=\"JavaScript\" type=\"text/javascript\">\
"<!--\n".
" function addDomain(element) {\n".
" var str = element.value; \n".
" if(str.search(/\@domain\.n
" element.value = element.value + \"@domain.net\";\n".
" }\n".
" }\n".
" function squirrelmail_loginpage_onl
...
html_tag( 'td',
'<input type="text" name="' . $username_form_name .'" value="' . $loginname_value .'" onChange="javascript:addDo
'left', '', 'width="*"' )
Business Accounts
Answer for Membership
by: jaysolomonPosted on 2003-11-04 at 09:00:34ID: 9679854
maybe this
>@jAy.com
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function addEmail(fObj){
fObj.value = fObj.value +"@jay.com";
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="text" name="email" onChange="addEmail(this);"
</form>
</body>
</html>