Page 1 of 1

spurious newline added!

Posted: Sat Dec 12, 2009 3:27 am
by DrPL
Hi,
I have a piece of Javascript code:

Code: Select all

            
var generated_div_text = '<div id="'+sanc_telephone+'">';
generated_html += generated_div_text;
 
But when I look at generated_div_text, I find that there is a line break inserted as follows:
<div id="
5558792065">
(the phone number is below and one character to the right of the quote mark
on the preceeding line)

Why is it doing this? I'm tearing my hair out!

Thanks

Paul

Re: spurious newline added!

Posted: Sat Dec 12, 2009 3:32 am
by John Cartwright
From the looks of it, your var sanc_telephone contains a newline at it's beginning. Where is that var contructed/appended?

Re: spurious newline added!

Posted: Sat Dec 12, 2009 3:46 am
by DrPL
Its obtained from an XML doucment and loaded as follows:

Code: Select all

var sanc_telephone = response.getElementsByTagName("telephone")[i].childNodes[0].nodeValue;

Re: spurious newline added!

Posted: Sat Dec 12, 2009 6:10 am
by John Cartwright
DrPL wrote:Its obtained from an XML doucment and loaded as follows:

Code: Select all

var sanc_telephone = response.getElementsByTagName("telephone")[i].childNodes[0].nodeValue;
Does this help?

Code: Select all

 
var sanc_telephone = response.getElementsByTagName("telephone")[i].childNodes[0].nodeValue;
sanc_telephone = sanc_telephone.replace(new RegExp("^[\r\n]+", "g"), "");
 

Re: spurious newline added!

Posted: Sat Dec 12, 2009 10:47 am
by DrPL
Thanks, I got it working! A shame I wasn't able to do exactly what I wanted to do though.... :cry:

Re: spurious newline added!

Posted: Sat Dec 12, 2009 5:27 pm
by DrPL
OK, I might as well add a link to my project in the hope that someone can help. Its at http://www.paullee.com/secondchance/ - its a bit of Ajax and googlemaps. I'm trying
to link a marker's mouseover/mouseout event hander to a div to color the background
when the icon hovers over an arrow. The problem lies in the mouseout event
- the error window say that document.getElementById( removeNL(tel_no_string) ) is null.
I'm perplexed as to why though!