File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes \ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "\" vs Watch "\" vs New topic

\" vs '

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

im a bit confused. here is some code from a servlet i wrote when i knew what i was doing
as usual, ignore the underscore in on_Click, it's just there because UBB wont allow exact code.
PrintWriter out = response.getWriter();
"<input type='button' value ='Go To Checkout' on_Click=\"parent.location='" + name + "'\"></form></td></tr>");
why can i use ' for the values 'button' and 'Go To Checkout', but have to use \" for the onClick value? and why inside the \" i can use ' and "?
i think it is because the quotes around button are optional but they are required for the onClick value. can anyone verify that or elaborate?
[ August 07, 2002: Message edited by: Randall Twede ]

Visit my download page
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
Looks to me like you did it this way because you have three levels of quotes: one for the servlet, one for the HTML, and one for JavaScript. AFAIK, on_click doesn't care what kind of quotes you use; neither does JavaScript.
Hope that helps..
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
Hi Randell,
If I understand you correctly Garann is correct. You can use whatever quotes, whether single or double, you want but once within a set of either you cannot use it again unless it is escaped since the code is looked at in a linear fashion. Once a second double quote is found in the string, that is is bound by double quotes, that isn't escaped (i.e. "......"....") then the string is terminated at the second double quote leaving basically garbage afterward that the compiler or interpreter will try to interpret as code. I hope this is what you were looking for and that I wasn't just babbling.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

thanks guys. maybe i should try changing it and see. there is a good chance i used \" because the person i was probably copying did it that way
I agree. Here's the link:
subject: \" vs '
jQuery in Action, 3rd edition