Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Updating multiple input fields using one select box.

Posted on 2004-04-21
4
Medium Priority
?
992 Views
Last Modified: 2009-12-16
I'm trying to automatically populate three input fields by using one select (combo box) field.  The select field contains names, when a name is selected, their home, cell, and work phone numbers need to be populated into the three input fields.

Does anyone have any ideas about how to do this?

Here's the code for the select and input fields:

<select size="1" name="em_name1" class="input_shadowless">
<option>Select</option>
<option>User 1</option>
<option>User 2</option>
<option>User 3</option>
</select>
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_work_phone1">
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_cell_phone1">
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_home_phone1">

My knowledge of JavaScript is extremely small, so spelling it out plainly would greatly help!!

Thanks,
Steve
0
Comment
Question by:scross1276
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 200 total points
ID: 10878734
<script>

function user(p1,p2,p3) {
  this.p1=p1;
  this.p2=p2;
  this.p3=p3;
}

users = new Array(
new user('','',''),
new user('123123','31123123','234234'),
new user('223123','41123123','634234'),
new user('323123','51123123','734234')
)
function fill(sel) {
  frm = sel.form; // get the form the sel is in
  frm.em_work_phone1.value = users[sel.selectedIndex].p1
  frm.em_cell_phone1.value= users[sel.selectedIndex].p2
  frm.em_home_phone1.value= users[sel.selectedIndex].p3
}
</script>
<form>

<select size="1" name="em_name1" class="input_shadowless"
onCHange="fill(this)">
<option>Select</option>
<option>User 1</option>
<option>User 2</option>
<option>User 3</option>
</select>
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_work_phone1">
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_cell_phone1">
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_home_phone1">
</form>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 10878775
So the "user" function is used to create a user object that has 3 attributes, p1, p2, p3 (could be changed in the script to workphone cellphone, homephone
We then create a users array (list) of 4 times a user
the first has empty values to clear the fields when the 0th option (Select) is chosen

The keyword (this) is used to pass the actual select to the function fill

Michel
0
 

Author Comment

by:scross1276
ID: 10878809
What can I say mplungjan, you're awesome!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10878876
Like this:


<html>
<head>
<script>
var nameTab = [
["", "", ""],
["work+U1", "cell+U1", "home+U1"],
["work+U2", "cell+U2", "home+U2"],
["work+U3", "cell+U3", "home+U3"]];
function setFields(theSel){
  theUser = nameTab[theSel.selectedIndex];
  theForm = theSel.form;
  theForm.em_work_phone1.value = theUser[0];
  theForm.em_cell_phone1.value = theUser[1];
  theForm.em_home_phone1.value = theUser[2];
}
</script>
</head>
<body>
<form>
<select size="1" name="em_name1" class="input_shadowless" onChange="setFields(this)">
<option>Select</option>
<option>User 1</option>
<option>User 2</option>
<option>User 3</option>
</select>
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_work_phone1">
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_cell_phone1">
<input class="input_shadowless" size=19 maxlength="50" type="text" name="em_home_phone1">
</form>
</body>
</html>


0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question