Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a string URL into javascript 1

Status
Not open for further replies.

gtubb

Programmer
Jan 15, 2004
24
GB
Hi folks

I can handle ASP, but I'm a bit of a novice at Javascript.

I have a working javascript slide show function. I want to pass a URL from a hidden form field into the script like so:

Pic[1] = '<%=request.form("picture2")%>'

This puts the URL of the picture into the script, but strips out all the forward slashes, making it useless.

How do I pass the string into the script with the slashes in place?

I hope someone can help - I've spent houyrs trying to figure it out!
 
Pic[1] = '<%=replace(request.form("picture2"),"\","\\")%>'

Known is handfull, Unknown is worldfull
 
Many thanks - it works!

This might seem a dumb question, but why does js remove the slashes in the first place?

 

It doesn't remove them as such... It treats backslash characters as escape characters, so in combination with the succeeding character, they tell JS to insert a special character. To present backslashes to JS, you need to escape them with a backslash, so:

Code:
var myString = 'c:\\program files\\myfile.txt';

Other escape combinations include '\n' (newline) and '\t' (tab)

Hope this helps,
Dan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top