Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Need help with replace()
Old 09-10-2008, 01:40 PM Need help with replace()
Skilled Talker

Posts: 53
Name: Dave
Location: Kansas, USA
Trades: 0
I have some code I have to fix with the following:

Code:
document.frmNewHireRpt.action=source;
document.frmNewHireRpt.target="_blank";
document.frmNewHireRpt.submit();
The problem is that the URL in source contains spaces and other chars that need to be URL encoded. But JavaScript doesn't seem to have a URLEncode function.

I am looking for a somewhat generic regular expression to use with Replace to URL encode a string (I don't use JavaScript that much).

Thanks!

--Dave
dnavarrojr is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-10-2008, 01:46 PM Re: Need help with replace()
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Check out javascript's escape() function.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 09-10-2008, 02:56 PM Re: Need help with replace()
Skilled Talker

Posts: 53
Name: Dave
Location: Kansas, USA
Trades: 0
Bingo!
dnavarrojr is offline
Reply With Quote
View Public Profile
 
Old 09-10-2008, 03:10 PM Re: Need help with replace()
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
encodeURI()
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-11-2008, 06:08 AM Re: Need help with replace()
Average Talker

Posts: 25
Trades: 0
encodeURI Method

Returns a string encoded as a valid Uniform Resource Identifier (URI)
function encodeURI(URIString : String) : String Arguments

URIString Required. A string representing an encoded URI.

Remarks

The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: ":", "/", ";", and "?". Use encodeURIComponent to encode these characters.

Last edited by softhink; 09-11-2008 at 06:09 AM..
softhink is offline
Reply With Quote
View Public Profile
 
Old 09-11-2008, 01:41 PM Re: Need help with replace()
Skilled Talker

Posts: 53
Name: Dave
Location: Kansas, USA
Trades: 0
Hmm.. escape() actually ended up working. But I'll give encodeURI() a try as well.
dnavarrojr is offline
Reply With Quote
View Public Profile
 
Old 09-11-2008, 01:44 PM Re: Need help with replace()
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
And, it always has for me too. However, a URL is a URI (but not all URIs are URLs), so you should use the encodeURI() Chris recommended to account for those scenarios we've not encountered yet, but which will otherwise be valid.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Need help with replace()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27566 seconds with 12 queries