Solved

getting rid of spaces

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now