Solved

getting rid of spaces

Posted on 2014-03-27
5
151 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

828 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