Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript nested quotes

Posted on 2008-10-15
4
Medium Priority
?
632 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 375 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

636 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