Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2009, 03:10 PM   PM User | #1
finstah1
Regular Coder

 
Join Date: May 2004
Location: The First State
Posts: 233
Thanks: 9
Thanked 0 Times in 0 Posts
finstah1 is an unknown quantity at this point
DOM help create text node??

Hi all,

I have a form that is passing data to another page. I want to display the data by an id so I can use that show the id if data !='' and hide if ="".
Here's the first part of the code:

Code:
 <tr valign="top">
                  <td>1.</td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e00_rep" onblur="CheckField(this.form,this,'');" /></td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e00_repemail" onblur="CheckField(this.form,this,'');" /></td>
                </tr>
                <tr valign="top">
                  <td>2.</td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e01_rep" /></td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e01_repemail" /></td>
                </tr>
                <tr valign="top">
                  <td>3.</td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e02_rep" /></td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e02_repemail" /></td>
                </tr>
                <tr valign="top">
                  <td>4.</td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e03_rep" /></td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e03_repemail" /></td>
                </tr>
                <tr valign="top">
                  <td>5.</td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e04_rep" /></td>
                  <td><input type="text" size="30" maxlength="50" name="wcsave_e04_repemail" /></td>
                </tr>
2nd part(next page) I'm looping thru inputs looking for "wcsave_e" prefix with any values. This data is then emailed:
Code:
<script  type="text/javascript">
var rx = /^wcsave_e/;
var d = "";
for (var i=0; i < document.getElementsByTagName("input").length; i++){
if(rx.test(document.getElementsByTagName("input")[i].name)){	
    if (document.getElementsByTagName("input")[wi.name.substring(0,10) != d) {
    document.write("<br />");
    d = document.getElementsByTagName("input")[i].name.substring(0,10);
    }
    document.write("<style='line-height: 8px;'>" +    document.getElementsByTagName("input")[i].value + " ");
    }
 }					
</script>
But as you can see I can't assign a variable for ALL the fields. (I need a variable assigned on the email, something like: wcsave_e99 = wcsave_e0, e1, e2, etc.)

Can I use getElementById and create a new variable that holds all values submitted? Ugh, does this make sense?

I'm wondering if I can use createText node so the entire row in step 2 above doesn't show if there are no values.
finstah1 is offline   Reply With Quote
Old 02-06-2009, 03:47 PM   PM User | #2
finstah1
Regular Coder

 
Join Date: May 2004
Location: The First State
Posts: 233
Thanks: 9
Thanked 0 Times in 0 Posts
finstah1 is an unknown quantity at this point
I reworked it to this:

Code:
<div id='reps'></div>  
<script type="text/javascript">
function addVal(retVal,inVal) {
  if (retVal.length > 0) {retVal=retVal+", "+inVal;} 
  else {retVal=inVal;}
  return retVal;
}
			
function checkAcc(){
var myAcc = "";
var Rep0 = document.getElementById("wcsave_e00_rep");	
var RepEmail0 = document.getElementById("wcsave_e00_repemail");	
var Rep1 = document.getElementById("wcsave_e01_rep");	
var RepEmail1 = document.getElementById("wcsave_e01_repemail");	
var Rep2 = document.getElementById("wcsave_e02_rep");	
var RepEmail2 = document.getElementById("wcsave_e02_repemail");	
var Rep3 = document.getElementById("wcsave_e03_rep");	
var RepEmail3 = document.getElementById("wcsave_e03_repemail");	
var Rep4 = document.getElementById("wcsave_e04_rep");	
var RepEmail4 = document.getElementById("wcsave_e04_repemail");	
var Rep00 = document.getElementById("wcsave_z00_Reps");
				
if (Rep0.value != "") 
myAcc = addVal(myAcc,Rep0.value);
if(RepEmail0.value != "")
myAcc = addVal(myAcc,RepEmail0.value);					
if (Rep1.value != "") 
myAcc = addVal(myAcc,Rep1.value);					
if(RepEmail1.value != "")
myAcc = addVal(myAcc,RepEmail1.value);					
if (Rep2.value != "") 
myAcc = addVal(myAcc,Rep2.value);
if(RepEmail2.value != "")
myAcc = addVal(myAcc,RepEmail2.value);					
if (Rep3.value != "") 
myAcc = addVal(myAcc,Rep3.value);
if(RepEmail3.value != "")
myAcc = addVal(myAcc,RepEmail3.value);
if (Rep4.value != "") 
myAcc = addVal(myAcc,Rep4.value);
if(RepEmail4.value != "")
myAcc = addVal(myAcc,RepEmail4.value);
Rep00.value = myAcc;			
}	
checkAcc();
document.getElementById('reps').innerHTML = document.getElementById("wcsave_z00_Reps").value;				
</script>
Works fine, could probably put it in a loop to route thru all the Reps and RepEmail. The only issue is at this:
Code:
{retVal=retVal+", "+inVal;}
returns:

jane doe, jane@udel.edu, john doe, john@udel.edu

I'm trying to get it to display like:
jane doe (jane@udel.edu)
john doe (john@udel.edu)

If I add "(" instead of "," in the retVal I still have the same problem.

How do I add a line break AFTER each rep and email? jane doe (jane@udel.edu)
finstah1 is offline   Reply With Quote
Old 02-06-2009, 04:04 PM   PM User | #3
finstah1
Regular Coder

 
Join Date: May 2004
Location: The First State
Posts: 233
Thanks: 9
Thanked 0 Times in 0 Posts
finstah1 is an unknown quantity at this point
I figured it out for anyone that needs this type of script.

Code:
<div id='reps'></div>  
			<script type="text/javascript">
			function addVal(retVal,inVal) {
				if (retVal.length > 0) {
					retVal=retVal+"; "+inVal;} 
				else {retVal=inVal;}
				return retVal;
			}
			
			function addVal2(retVal,inVal) {
				if (retVal.length > 0) {
						retVal=retVal+", "+inVal;}
				else {retVal=inVal;}
				return retVal;
			}
			
			function checkAcc(){
				var myAcc = "";
				var Rep0 = document.getElementById("wcsave_e00_rep");	
				var RepEmail0 = document.getElementById("wcsave_e00_repemail");	
				var Rep1 = document.getElementById("wcsave_e01_rep");	
				var RepEmail1 = document.getElementById("wcsave_e01_repemail");	
				var Rep2 = document.getElementById("wcsave_e02_rep");	
				var RepEmail2 = document.getElementById("wcsave_e02_repemail");	
				var Rep3 = document.getElementById("wcsave_e03_rep");	
				var RepEmail3 = document.getElementById("wcsave_e03_repemail");	
				var Rep4 = document.getElementById("wcsave_e04_rep");	
				var RepEmail4 = document.getElementById("wcsave_e04_repemail");	
				var Rep00 = document.getElementById("wcsave_z00_Reps");
				
				if (Rep0.value != "") 
					myAcc = addVal(myAcc,Rep0.value);
				if(RepEmail0.value != "")
					myAcc = addVal2(myAcc,RepEmail0.value);					
				if (Rep1.value != "") 
					myAcc = addVal(myAcc,Rep1.value);					
				if(RepEmail1.value != "")
					myAcc = addVal2(myAcc,RepEmail1.value);					
				if (Rep2.value != "") 
					myAcc = addVal(myAcc,Rep2.value);
				if(RepEmail2.value != "")
					myAcc = addVal2(myAcc,RepEmail2.value);					
				if (Rep3.value != "") 
					myAcc = addVal(myAcc,Rep3.value);
				if(RepEmail3.value != "")
					myAcc = addVal2(myAcc,RepEmail3.value);
				if (Rep4.value != "") 
					myAcc = addVal(myAcc,Rep4.value);
				if(RepEmail4.value != "")
					myAcc = addVal2(myAcc,RepEmail4.value);
				Rep00.value = myAcc;			
				}	
				checkAcc();
				document.getElementById('reps').innerHTML = document.getElementById("wcsave_z00_Reps").value;				
			</script>
finstah1 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:35 AM.


Advertisement
Log in to turn off these ads.