• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

\" vs '

 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Garann Means
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Hunter
Ranch Hand
Posts: 832
  • 0
  • Mark post as helpful
  • send pies
  • 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: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic