• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

\" vs '

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic