Solved

Javascript nested quotes

Posted on 2008-10-15
4
625 Views
Last Modified: 2012-08-13
Can somebody help me with the following code:

var pickid = "testPickId";
setTimeout('ajaxPickingListAction("PickingList.Action.ReversePick.Confirm.php?pickid="'+ pickid +')',3000);

There is problem with my quotes. Note that pickid is a variable

the ultimate objective is to how to get the setTimeout run with my code..

thanks
0
Comment
Question by:encus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:najh
ID: 22719482
that's actually confusing, but to start with, i assume that it should end with the same quote as you started with... so the end should be 3000'); shouldn't it?

which is the variable to it? if it's just the pickid which changes, then maybe you could write:
setTimeout(ajaxPickingListAction("PickingList.Action.ReversePick.Confirm.php?pickid="+ pickid ), 3000);
0
 
LVL 27

Accepted Solution

by:
BigRat earned 125 total points
ID: 22719938
You're doing too much at once and running out of quotes :-

var pickid = "testPickId";
var command = 'ajaxPickingListAction("PickingList.Action.ReversePick.Confirm.php?pickid="'+ pickid + ')';
setTimeout(command,3000);

and even :-

var pickid = "testPickId";
var url = 'PickingList.Action.ReversePick.Confirm.php?pickid='+ escape(pickid);
var command = 'ajaxPickingListAction("' + url + '")';
setTimeout(command,3000);

I split such actions up into pieces, they become much simpler to modify. Note that SetTimeout takes a string which is executed with (effectively) eval(). Note also that when sending anything to the server, the data ought to be escaped. In your example of course it is a constant (pickid), so it is strictly not necessary. But as I said, when you modify things .............


0
 

Author Comment

by:encus
ID: 22720978
Thx BigRat, this is the way actually I am doing also, but just trying to put everything in one line as I have got too much codes that needs to be modulised.

Anyway thank you so much for the solution, and just to check with you is the escape() equivalent to mysql_escape_string() in php?
0
 
LVL 27

Expert Comment

by:BigRat
ID: 22721111
Answer to your question : Probably.

When you actually send data from an HTML page to the server you MUST escape the data to avoid certain characters. The browser does this automatically from input, textarea and other elements. There are less problems when one sends the data via POST (usually AJAX), but not escaping for example a space, can lead to a failure to access the server.

When constructing URLs in the server on making an HTML page one must again escape the query parts of the URL in the same way. This again is not so serious as most browsers, on processing a link in an HTML page, will escape them for you.
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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

729 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