Solved

getting rid of spaces

Posted on 2014-03-27
5
147 Views
Last Modified: 2014-03-27
I have some code that I am trying to use for a link.  However, the spaces are messing up that link.  How can I get rid of them?

I tried this but my code just errors out.  

+ "<br> <a href=" + str_replace(" ", "%20", graphic.attributes.SAPALINK) + ">SAPA Report</a>"

Thanks I'm hoping for a simple solution here.  FWIW - This is in a mapping application and going inside an info box but it is using javascript to do so.
0
Comment
Question by:flfmmqp
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39958930
Assuming the field is called graphic.attributes.SAPALINK

then:
<a href=" + graphic.attributes.SAPALINK.str_replace(" ", "%20") + ">SAPA Report</a>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39958933
add simple quote around for the href and use encodeURIComponent :

+ "<br> <a href='" + encodeURIComponent(graphic.attributes.SAPALINK) + "'>SAPA Report</a>"
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39958944
Or leakim971's option! Always forget about encodeURIComponent!

Much better than replacing characters.
0
 

Author Closing Comment

by:flfmmqp
ID: 39959105
You answer helped me quickly get to this.  Which seems to be working.  Whohoo  Thanks

+ "<br> <a href='" + graphic.attributes.SAPALINK + "'>SAPA Report</a>"
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39959180
Yes, the encodeURIComponen as it's your link not a parameter for your link
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now