By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Script to auto fill fields based on other fields

P: n/a
G'day everyone

I'm not a JavaScript programmer, so I wonder if you could point me in
the right direction or simply tell me how to do the following.

I'd like to submit a patch for the registration page of Pootle
servers. Pootle is a GPL system for translation of software (usually
volunteer work).

What happens is that when a user registers, he fills in his real name,
his preferred user name, and his e-mail address. I would like to add
two more fields, but I want those fields filled in automatically based
on what the user filled in in the previous fields... although if the
user wants to change the information before submitting the form, he
should be able to do so.

At the moment, the fields are:

Username: [_____________]
Real name: [_____________]
E-mail: [______________]

I want to have to more fields:

Display name (public): [________________]
Display name (private): [________________]

If the user's real name is Joe Soap, and his mail address is
jo*@soap.com, I want the public display name to be this:

Joe Soap <joe[at]soap[dot]com>

....and I want the private display name to be this:

Joe Soap <jo*@soap.com>

By filling in this information automatically, I remove the need to
explain to the user what kind of information I want in there. If the
user decides that he does not want to display his name, he can delete
it or further munge it before pressing "Submit".

Ideally, I want the information filled in automatically (either in
real time or when the user's cursor leaves the field) but a solution
that requires the user to press a button or buttons next to the fields
would also be fine.

Is this fairly simple to do? I hope so :-)

Thanks in advance
Samuel (aka leuce, voetleuce)
Sep 16 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Sep 16, 10:14*am, Samuel Murray <le...@absamail.co.zawrote:
G'day everyone

I'm not a JavaScript programmer, so I wonder if you could point me in
the right direction or simply tell me how to do the following.

I'd like to submit a patch for the registration page of Pootle
servers. *Pootle is a GPL system for translation of software (usually
volunteer work).

What happens is that when a user registers, he fills in his real name,
his preferred user name, and his e-mail address. *I would like to add
two more fields, but I want those fields filled in automatically based
on what the user filled in in the previous fields... although if the
user wants to change the information before submitting the form, he
should be able to do so.

At the moment, the fields are:

Username: [_____________]
Real name: [_____________]
E-mail: [______________]

I want to have to more fields:

Display name (public): [________________]
Display name (private): [________________]

If the user's real name is Joe Soap, and his mail address is
j...@soap.com, I want the public display name to be this:

Joe Soap <joe[at]soap[dot]com>

...and I want the private display name to be this:

Joe Soap <j...@soap.com>

By filling in this information automatically, I remove the need to
explain to the user what kind of information I want in there. *If the
user decides that he does not want to display his name, he can delete
it or further munge it before pressing "Submit".

Ideally, I want the information filled in automatically (either in
real time or when the user's cursor leaves the field) but a solution
that requires the user to press a button or buttons next to the fields
would also be fine.

Is this fairly simple to do? *I hope so :-)

Thanks in advance
Samuel (aka leuce, voetleuce)
What you are looking for is RegEx, it makes sense to run a script when
e-mail address (as it is last in your display) looses focus -
concatenate "Real name" and "E-mail" to get the "Display name
(private)" and then use RegEx to replace @ and .(s) with your
replacement strings...
Use Google to find RegEx [Regular Expressions] tutorials
Sep 16 '08 #2

P: n/a
Samuel Murray wrote:
Username: [_____________]
Real name: [_____________]
E-mail: [______________]
I want to have to more fields:
Display name (public): [________________]
Display name (private): [________________]

If the user's real name is Joe Soap, and his mail address is
j...@soap.com, I want the public display name to be this:
Joe Soap <joe[at]soap[dot]com>
...and I want the private display name to be this:
Joe Soap <j...@soap.com>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Regular Expression</title>
<script type="text/javascript">
function writenew() {
var f = document.forms[0];
var e = f.email.value.replace(/@/, '[at]');
e = e.replace(/\.([a-z]{2,6}$)/i, '[dot]$1');
f.public.value = f.username.value + ' <' + e + '>';
f.private.value = f.username.value + ' <' + f.email.value + '>';
}
</script>
</head>
<body>
<form method="get" action="#">
<pre>
Username : <input name="username" onKeyUp="writenew()">
Real name: <input name="realname" onKeyUp="writenew()">
E-mail : <input name="email" onKeyUp="writenew()">
Public : <input name="public">
Private : <input name="private">
</pre>
</form>
</body>
</html>

Hope this helps,

--
Bart
Sep 17 '08 #3

P: n/a
On 17 Sep, 17:20, Bart Van der Donck <b...@nijlen.comwrote:
Samuel Murray wrote:
Username: [_____________]
Real name: [_____________]
E-mail: [______________]
I want to have to more fields:
Display name (public): [________________]
Display name (private): [________________]
If the user's real name is Joe Soap, and his mail address is
j...@soap.com, I want the public display name to be this:
Joe Soap <joe[at]soap[dot]com>
...and I want the private display name to be this:
Joe Soap <j...@soap.com>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
*"http://www.w3.org/TR/html4/strict.dtd">
<html>
*<head>
* <title>Regular Expression</title>
* <script type="text/javascript">
* *function writenew() *{
* * var f = document.forms[0];
* * var e = f.email.value.replace(/@/, '[at]');
* * e = e.replace(/\.([a-z]{2,6}$)/i, '[dot]$1');
* * f.public.value = f.username.value + ' <' + e + '>';
* * f.private.value = f.username.value + ' <' + f.email.value + '>';
* *}
* </script>
*</head>
*<body>
* <form method="get" action="#">
* *<pre>
* * Username : <input name="username" onKeyUp="writenew()">
* * Real name: <input name="realname" onKeyUp="writenew()">
* * E-mail * : <input name="email" onKeyUp="writenew()">
* * Public * : <input name="public">
* * Private *: <input name="private">
* *</pre>
* </form>
*</body>
</html>

Hope this helps,

--
*Bart
Hello!

I wan´t a function like this but my first field is the email.

email: ______________

name: _______________
hompage: ________________
company: _______________
I want the form to do this:

email: Jo*****@mycompany.com

name: Joe Doh <---Autofilled
homepage: http://www.mycompany.com <--- autofilled
company: Mycompany <--- autofilled

All the autofilled parts can you edit after as the orginal script.

Hope you can help me!


Sep 25 '08 #4

P: n/a
On 26 Sep, 00:05, vik...@3on.se wrote:
On 17 Sep, 17:20, Bart Van der Donck <b...@nijlen.comwrote:


Samuel Murray wrote:
Username: [_____________]
Real name: [_____________]
E-mail: [______________]
I want to have to more fields:
Display name (public): [________________]
Display name (private): [________________]
If the user's real name is Joe Soap, and his mail address is
j...@soap.com, I want the public display name to be this:
Joe Soap <joe[at]soap[dot]com>
...and I want the private display name to be this:
Joe Soap <j...@soap.com>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
*"http://www.w3.org/TR/html4/strict.dtd">
<html>
*<head>
* <title>Regular Expression</title>
* <script type="text/javascript">
* *function writenew() *{
* * var f = document.forms[0];
* * var e = f.email.value.replace(/@/, '[at]');
* * e = e.replace(/\.([a-z]{2,6}$)/i, '[dot]$1');
* * f.public.value = f.username.value + ' <' + e + '>';
* * f.private.value = f.username.value + ' <' + f.email.value + '>';
* *}
* </script>
*</head>
*<body>
* <form method="get" action="#">
* *<pre>
* * Username : <input name="username" onKeyUp="writenew()">
* * Real name: <input name="realname" onKeyUp="writenew()">
* * E-mail * : <input name="email" onKeyUp="writenew()">
* * Public * : <input name="public">
* * Private *: <input name="private">
* *</pre>
* </form>
*</body>
</html>
Hope this helps,
--
*Bart

Hello!

I wan´t a function like this but my first field is the email.

email: ______________

name: _______________
hompage: ________________
company: _______________

I want the form to do this:

email: Joe....@mycompany.com

name: Joe Doh * <---Autofilled
homepage:http://www.mycompany.com*<--- autofilled
company: Mycompany <--- autofilled

All the autofilled parts can you edit after as the orginal script.

Hope you can help me!- Dölj citerad text -

- Visa citerad text -
Anyone??
Sep 29 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.