loop thru 5 text fields and display all 5 values

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

jaxson9875Asked:
Who is Participating?
 
MorcalavinCommented:
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
 
MorcalavinCommented:
You may want to do:
emailAll.value += inp[y].value + "\n";
or
emailAll.value = emailAll.value + inp[y].value + "\n";

0
 
jaxson9875Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.