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);

}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.