Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

JavaScript string concatenation problem.


  • Please log in to reply
3 replies to this topic

#1 Ray Parrish

Ray Parrish

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:08:59 AM

Posted 20 March 2010 - 05:20 AM

Hello,

The following code is producing the string of output in the code box below it. Can anyone please explain to me why it is breaking the string "Average Price Per Click" into average="", price="", etc???

for (weekNumber in weeklyCPC) {
		  graphbodyHTML = graphbodyHTML + "<div class=\"bar\" id=\"bar" + (weekNumber + 1) + " title=\"$ " + weeklyCPC[weekNumber] + " Average Price Per Click\" style=\"position: absolute; left: " + ((100.0 / 52) * weekNumber) + "%; height: " + ((100.0 / rangeSize) * weeklyCPC[weekNumber]) + "%; width: " + (100.0 / 52) + "%;\"></div>";
		  weekNumber ++;
	 }

<div class="bar" id="bar01 title=" $="" 0.09="" average="" price="" per="" click="" style="position:
 absolute; left: 0%; height: 90%; width: 1.92308%;"></div>

What I want to output is the following -

<div class="bar" id="bar01 title="$ 0.09 Average Price Per Click" style="position:
 absolute; left: 0%; height: 90%; width: 1.92308%;"></div>

Thanks for any help you can be.

Ray Parrish

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:59 AM

Posted 20 March 2010 - 08:23 AM

Here is a tip that might help. In Javascript, strings can be enclosed in single quotes. Then you do not have to escape your quotation marks, so this:
"style=\"color:red\;""
becomes this:
'style="red"'
It gets a bit easier to track quotes.

If you look at the actual code that is being output, you will see that you are missing a quotation mark after id=bar01. Your code reads: id="bar01

#3 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:08:59 AM

Posted 20 March 2010 - 12:15 PM

Here is a tip that might help. In Javascript, strings can be enclosed in single quotes. Then you do not have to escape your quotation marks, so this:
"style=\"color:red\;""
becomes this:
'style="red"'
It gets a bit easier to track quotes.

If you look at the actual code that is being output, you will see that you are missing a quotation mark after id=bar01. Your code reads: id="bar01


Thank you for that, I was missing it, and adding a back slash quote fixed that problem. I'll change over to single quotes as I go on the rest of this project as well also.

Now to pose a Python question in another thread.

Thanks again, Ray Parrish

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:59 AM

Posted 20 March 2010 - 12:20 PM

String concatenation can be tough to track. :*)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users