0

Greetings.
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')">

<script>
  function sortTable(arg1){
    if(sortTable.arguments.length > 1)
      alert(sortTable.arguments[1]);
  }
</script>

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.

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by alpha_foobar
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.