spurious newline added!

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
DrPL
Forum Commoner
Posts: 26
Joined: Wed Oct 07, 2009 4:22 pm

spurious newline added!

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: spurious newline added!

Post 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?
DrPL
Forum Commoner
Posts: 26
Joined: Wed Oct 07, 2009 4:22 pm

Re: spurious newline added!

Post 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;
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: spurious newline added!

Post 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"), "");
 
DrPL
Forum Commoner
Posts: 26
Joined: Wed Oct 07, 2009 4:22 pm

Re: spurious newline added!

Post by DrPL »

Thanks, I got it working! A shame I wasn't able to do exactly what I wanted to do though.... :cry:
DrPL
Forum Commoner
Posts: 26
Joined: Wed Oct 07, 2009 4:22 pm

Re: spurious newline added!

Post 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!
Post Reply