Solved

Javascript nested quotes

Posted on 2008-10-15
4
620 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now