Jump to content

text aligning problem using createTextNode


cardfan

Recommended Posts

Having a problem with createTextNode, every area of my document using createTextNode leaves a space on the first line when there is multiple lines of ouput, this leaves the 2nd line out of alignment. ...any ideas?

 

Have no style formatting or anything else that would effect the output

 

Thanks

 

//////////////////////////////////////////////////////////////////////////////

output

 

test

test, AK 22222

 

/////////////////////////////////////////////////////////////////////////////////

Here's a snippet of the code

 

if(streetNum != ""){

strAddress = streetNum +" "+street;

}

else{

strAddress = street;

}

 

//insert text

txtNode = document.createTextNode(strAddress);

document.getElementById("address").appendChild(txtNode);

//add break here

var lineBreak = document.createElement("br");

document.getElementById("address").appendChild(lineBreak);

 

 

if(crossStreet != ""){

strAddress = " & "+crossStreet;

 

//insert text

txtNode = document.createTextNode(strAddress);

document.getElementById("address").appendChild(txtNode);

//add break here

var lineBreak = document.createElement("br");

document.getElementById("address").appendChild(lineBreak);

}

 

 

I'm not seeing anything in the assignments that is causing a space, here's the output from php to Javascript vars

 

//populate address info

var streetNum = "<?php echo trim($row_results['streetnum']);?>";

var street = "<?php echo trim($row_results['street']);?>";

var crossStreet = "<?php echo trim($row_results['crossstreet']);?>";

var suiteNum = "<?php echo trim($row_results['suitenum']);?>";

var city = "<?php echo trim($row_results['city']);?>";

var state = "<?php echo trim($row_results['state']);?>";

var zip = "<?php echo trim($row_results['zip']);?>";

 

 

************  Here's the page source

 

//populate address info

var streetNum = "1025";

var street = "test street";

var crossStreet = "test cross street";

var suiteNum = "205";

var city = "Columbia";

var state = "MO";

var zip = "65203";

 

*************  here's another sample of the indented output (space before the ampersand is ok, but the space before the 1025 is my issue can not get rid of it)

 

1025 test street

& test cross street

Suite Number 205

Columbia, MO 65203

 

*************  Here's the function

function outputAddress(){

 

var strAddress="";

var txtNode;

 

//txtNode = document.createTextNode(addrTxt);

 

 

if(streetNum != ""){

strAddress = streetNum +" "+street;

}

else{

strAddress = street;

}

 

//insert text

txtNode = document.createTextNode(strAddress);

document.getElementById("address").appendChild(txtNode);

//add break here

var lineBreak = document.createElement("br");

document.getElementById("address").appendChild(lineBreak);

 

 

if(crossStreet != ""){

strAddress = " & "+crossStreet;

 

//insert text

txtNode = document.createTextNode(strAddress);

document.getElementById("address").appendChild(txtNode);

//add break here

var lineBreak = document.createElement("br");

document.getElementById("address").appendChild(lineBreak);

}

 

if(suiteNum != ""){

strAddress = "Suite Number "+suiteNum;

 

//insert text

txtNode = document.createTextNode(strAddress);

document.getElementById("address").appendChild(txtNode);

//add break here

var lineBreak = document.createElement("br");

document.getElementById("address").appendChild(lineBreak);

 

}

 

strAddress = city + ", " + state +" "+ zip;

 

//insert text

txtNode = document.createTextNode(strAddress);

document.getElementById("address").appendChild(txtNode);

//add break here

var lineBreak = document.createElement("br");

document.getElementById("address").appendChild(lineBreak);

 

 

}

 

Thanks for looking at it rhodesa

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.