JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > FAQ > How can I put a String literal in a Javascript call, for instance in an onChange attribute
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  How can I put a String literal in a Javascript call, for instance in an onChange attribute
Added by scud, last edited by scud on Mar 30, 2006  (view change)
Labels: 
(None)

The problem is in escaping quotes and getting the double quotes around the final value, like we expect in HTML attributes. Here's an example of the right way to do this (thanks to John Brad):

onchange='"someFunc(this.form, \'abc\')"'

Notice here that there are single quotes surrounding the double quotes, and then the single quotes inline in the Javascript are escaped. This produces this result:

onchange="someFunc(this.form, 'abc')"
Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators