473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Array and form question

Hello - I have a little challenge here which I haven't been able to solve, and
thought you might help me.

I have a "Register a new member" page for groups of people. There is a group
leader that signs up new members to the group. I also have a member database
which is unrelated, but could be of help.

Basically, the group leader should be able to add any person, but the system
will later recognize if he hadded someone who is a registered member.

So, the form looks like this:

Email: [ ]
Name: [ ]
[add]

What I would like to do is that when the Email field looses focus, javascript
will iterate through an array I've created beforehand of known email addresses
and their corresponding names, and thus auto-filling the Name-field. Do you
understand?

How would you solve it?

--
Sandman[.net]
Jul 23 '05 #1
3 1036
Ron
Sandman wrote:
Hello - I have a little challenge here which I haven't been able to solve, and
thought you might help me.

I have a "Register a new member" page for groups of people. There is a group
leader that signs up new members to the group. I also have a member database
which is unrelated, but could be of help.

Basically, the group leader should be able to add any person, but the system
will later recognize if he hadded someone who is a registered member.

So, the form looks like this:

Email: [ ]
Name: [ ]
[add]

What I would like to do is that when the Email field looses focus, javascript
will iterate through an array I've created beforehand of known email addresses
and their corresponding names, and thus auto-filling the Name-field. Do you
understand?

How would you solve it?

I would use two corresponding arrays. Add an
onblur="fillOutForm(this.value)" attribute to your email element. The
fillOutForm() function could look like this:

function fillOutForm(emailAddress) {
var name = "";
for(i=0;i<emailArray.length;i++) {
if(emailAddress==emailArray[i]) {
name = nameArray[i];
}
}
document.getElementById("nameField").value = name;
}

If you wanted to use one array of "emailAddress=name" type entries, you
could use:

function fillOutForm(emailAddress) {
var name = "";
for(i=0;i<emailArray.length;i++) {
var pair=emailArray[i].split("=", 2);
if(emailAddress==pair[0]) {
name = pair[1];
}
}
document.getElementById("nameField").value = name;
}
Jul 23 '05 #2
Ron
Sandman wrote:
How would you solve it?

Sorry, you should probably add a check in the function to make sure that
the user filled in the email address at all before
bothering to iterate through an array. :P

if (emailAddress!="") {
doStuff...
}
Jul 23 '05 #3
Hello,

Use objects or 2 parallel arrays.

Here is an example of objects:

<script language="JavaScript">
<!--
var x = new Object;
x["us***@yahoo.com"] ="User #1";
x["us***@yahoo.com"] ="User #2";
x["us***@yahoo.com"] ="User #3";

for (y in x)
{
alert("email:" + y + " name:" + x[y]);
}
//-->
</script>

This sample shows how to iterate/add elements.

HTH
Elias
"Sandman" <mr@sandman.net> wrote in message
news:mr**********************@individual.net...
Hello - I have a little challenge here which I haven't been able to solve, and thought you might help me.

I have a "Register a new member" page for groups of people. There is a group leader that signs up new members to the group. I also have a member database which is unrelated, but could be of help.

Basically, the group leader should be able to add any person, but the system will later recognize if he hadded someone who is a registered member.

So, the form looks like this:

Email: [ ]
Name: [ ]
[add]

What I would like to do is that when the Email field looses focus, javascript will iterate through an array I've created beforehand of known email addresses and their corresponding names, and thus auto-filling the Name-field. Do you understand?

How would you solve it?

--
Sandman[.net]

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: M.Siler | last post by:
<HTML> <HEAD> <TITLE></TITLE> <SCRIPT> <!-- var factor_val = new Array(8,7) factor_val = 68.8 factor_val = 55
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
8
by: T. Wintershoven | last post by:
Hello all, I have a form with some checkboxes. The names of these checkboxes come from an array. When i click the submit button the resultcode doesn't recognize the names when i want to check...
3
by: kaarmen | last post by:
In html i have some question, and the answers are radio buttons ... the names of variables in html are array ... like question, question ... etc. and every question has multiple value, depending of...
3
by: karmenkrile | last post by:
In html i have some question, and the answers are radio buttons ... the names of variables in html are array ... like question, question ... etc. and every question has multiple value, depending...
6
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
Hey guys, I've searched high and low for a way to populate a vb array with data from a javascript array. I can find 50 ways to do it with ASP but not one for VB. I appreciate what help you can...
7
by: lawpoop | last post by:
Hello all - Is there a way to get a nested array in a $_POST variable? I have a form where there are several questions, each one corresponding to a database row. On submission of the form, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.