JavaScript - Use Of The Escape()
Hi,
i am new to Javascript i want to know what is the use of the escape() function i read it on w3schools that the function is to encode the string passed top it so as it convert into ascii format so that it can be transferred over any network, can anybody explain me this with an example. Please recommend Regards ltoso Similar Tutorialsall OK, appears as expeced Code: tmpHTML += "<input style = '" + "color:red;" + "' ... all I get is string "color:red" from whole line of code, no errors in javascript console Code: tmpHTML += "<input style = '" + (arr1[i].split("|")[1] != null)?"color:red;":"color:blue;"; + "'.... ? In my coding I have the following lines: Code: for (index = 0; index < slidesNumber; index++) { $('<a href="#"></a>') } Now I want to give each href a unique name with the index variable. So it should look like Code: $('<a href="#index"></a>') Problem is that it just displays the word 'index', and I don't know how to escape it, so that it displays the value of index. Who can help me out? What is the need of using escape() in javascript ? I am unable to understand this escape(). What happens if escape() is not used ? Can someone , please explain in detail ? Thanks Hi there, I have been told I need to use escape() and unescape() to fix some issues I am having with my Javascript in IE7. I've been fiddling with it for two days now and can't seem to get it working correctly. It would be amazing if someone on here could spare a few minutes to tell me what my code should look like. It already works fine as is in new browsers, but IE7 is the problem! Here's my Javascript (I've removed my efforts at escaping and unescaping, and also blanked my Facebook app ID out with 123456789): Code: <script> FB.init({ appId:'123456789', cookie:true, status:true, xfbml:true }); function shareProduct(captionvar, descriptionvar, picturevar) { FB.ui({ method: 'feed', link: 'http://www.facebook.com/rjthompsonmusic?sk=app_123456789', name: 'RJ Thompson Official Facebook Store', caption: captionvar, description: descriptionvar, pictu picturevar }); } </script> And here is how it is being called: Code: <a href="#" onclick="shareProduct('Illogical Life - Digital Download', 'RJ Thompsons 2006 album "Illogical Life" available for Digital Download from his Facebook Store. Includes the single "Green Eyed", live favourites "Jester" and "Piano Song", and 8 more original tracks. Only £7.49!', 'http://www.rjthompsonmusic.com/facebook/illogical_life_270.jpg')"> Facebook</a> Would really appreciate any help with this. Many thanks, Chris Code: <html> <body> <div id="link"> <a href="http://www.facebook.com/">Facebook</a> </div> <script type="text/javascript"> var addr=new Array(); addr[0]="http://www.google.com/"; addr[1]="http"//www.yahoo.com/"; addr[2]="http://www.bing.com/"; var rl=document.getElementById("link"); var ri=Math.floor(Math.random()*3); rl.innerHTML= </script> </body> </html> I got stuck in getting this to work (show random element of the array as a link with description) Code: rl.innerHTML='<a href="addr[ri]">addr[ri]</a>'; This is showing addr[ri] on a page and directs to www.domain.com/addr[ri] Thank you in advance for any info. Happy new Year, I need to use the escape() function to protect a string before sending it with a POST request. Alas , the function escape() is not supported on the Javascript engine used ( WITBE scenario doesn't support DOM specific functions ). Has anybody the code, in JAVAscript of this function ? Cos without it the POST request doesn't work as expected. Cheers, Didier. I have a form with an action url, but I need to alter it on submit. What I need to do is take the value of the text field, escape it, and append it on the end of the action url. Something like this: action url: /search/node appended action url: /search/node/some_escaped_string To do this, I create the function ahead of time and change the submit to a button with onClick. What isn't working is the escape mechanism. If I were to test for "ttt hhh", I'll get "/search/node/ttt hhh", instead of "/search/node/ttt%20hhh" Code: <script type="text/javascript"> function urlAppend() { termsValue = document.getElementById('terms').value; escapedVar = escape(termsValue); appendedUrl = "/search/node/" + escapedVar; location.href = appendedUrl; } </script> <form method="get" action="/search/node"> <input type="text" name="terms" id="terms"></input> <input type="button" value="Search" onClick="urlAppend();"> </form> Can someone tell me what I'm doing wrong? |