I encountered this little problem and am stuck. I don't know what should I google. I am developing a webpage with Coldfusion and I need to use some Javascript also.

I have a component, and onclick of that component, I would like to call a Javascript function and pass in some arguments - the arguments are gotten from some Coldfusion variables. I have made the function to run, but at the time of coding, I did not thought of this problem. So here it a little snippet.

<!-- html -->
<input type="button" value="Click me" onClick="sortTable(0, 'abcdef')">

  function sortTable(arg1){
    if(sortTable.arguments.length > 1)

The above code is just something similar to my program. That snippet works. But, if I pass in arguments[1] as 'this is hm's program' then the program fails. That is because of the ' symbol there. The error says, "expected )". I can't figure out what should I do to escape that.
Please advise.

Recommended Answers

All 2 Replies

Use double quotes around your string:

"this is hm's program"

you can also escape the character using a backslash... this way you can be sure that your arguments will be interpreted correctly... especially true if your page is being generated.

"this is hm\'s program"

the reason i like escaping these characters is i then know thatit will be safe using any javascript string syntax.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.