File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "\" vs Watch "\" vs New topic
Author

\" vs '

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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();
out.println(
.
.
.
"<input type='button' value ='Go To Checkout' on_Click=\"parent.location='http://www.javaguy.dns2go.com/examples/LastChance.jsp?name=" + 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 ]

SCJP
Visit my download page
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
Randall,
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..
g.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
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.
Rob
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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: http://aspose.com/file-tools
 
subject: \" vs '