?
Solved

getting rid of spaces

Posted on 2014-03-27
5
Medium Priority
?
165 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 83

Accepted Solution

by:
leakim971 earned 2000 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 83

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

840 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