Solved

loop thru 5 text fields and display all 5 values

Posted on 2009-04-02
3
285 Views
Last Modified: 2013-11-05
I have a table that has 5 email fields. I'm using the JS test parameter to search all form fields on the page that start with a06_emailid. I then want all 5 values to show but it seems to only display the last value.

What am I doing wrong that not all the values are displaying?
<script>
 function addMe(){
	var email1 = document.getElementById("a06_emailid1");	
	var email2 = document.getElementById("a06_emailid2");	
	var email3 = document.getElementById("a06_emailid3");		
	var email4 = document.getElementById("a06_emailid4");	
	var email5 = document.getElementById("a06_emailid5");
	var emailAll = document.getElementById("z00_emails");
	var rx = /^a06_emailid/;
			var inp = document.getElementsByTagName("input")
			for (var y=0; y < inp.length; y++) {
					if(rx.test(inp[y].name)){
						emailAll.value = inp[y].value + "\n";
					}
			}	
</script>
 
<table border="0" cellspacing="0" cellpadding="1">
<tr valign="top">
<td>1.</td>
<td><input type="text" size="30" maxlength="50" name="a06_emailid1" /></td>
</tr>
<tr valign="top">
<td>2.</td>
<td><input type="text" size="30" maxlength="50" name="a06_emailid2" /></td>
</tr>
<tr valign="top">
<td>3.</td>
<td><input type="text" size="30" maxlength="50" name="a06_emailid3" /></td>
</tr>
<tr valign="top">
<td>4.</td>
<td><input type="text" size="30" maxlength="50" name="a06_emailid4" /></td>
</tr>
<tr valign="top">
<td>5.</td>
<td><input type="text" size="30" maxlength="50" name="a06_emailid5" /></td>
 </tr>
 </table>

Open in new window

0
Comment
Question by:jaxson9875
[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
3 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 24051673
You may want to do:
emailAll.value += inp[y].value + "\n";
or
emailAll.value = emailAll.value + inp[y].value + "\n";

0
 

Author Comment

by:jaxson9875
ID: 24052293
beautiful! Thanks!

the += worked. Just for my reference, what exactly does the += do?

Also is there a way to show the results with comma's as opposed to line breaks?
0
 
LVL 18

Accepted Solution

by:
Morcalavin earned 25 total points
ID: 24052474
var this = that;    //You set this equal to that.  If you are in a loop, the value of this is overwritten with the value of that each time you go through the loop.  You are basically "resetting" the variable every time;

var this += that   //this is the same as this = this + that.  You want to set the value of this, to what is currently the value of this PLUS the value of that.

Just use "," instead of  "\n" to separate by commas.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

728 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