944,209 Members | Top Members by Rank

Ad:
Jun 30th, 2005
0

Arguments of a function

Expand Post »
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.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!-- html -->
  2. <input type="button" value="Click me" onClick="sortTable(0, 'abcdef')">
  3.  
  4. <script>
  5. function sortTable(arg1){
  6. if(sortTable.arguments.length > 1)
  7. alert(sortTable.arguments[1]);
  8. }
  9. </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.
Similar Threads
Reputation Points: 53
Solved Threads: 1
Posting Whiz
red_evolve is offline Offline
313 posts
since Jun 2003
Jul 1st, 2005
0

Re: Arguments of a function

Use double quotes around your string:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. "this is hm's program"
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Jul 4th, 2005
0

Re: Arguments of a function

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.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. "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.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: How do I open a web page with several layers to a spacific layer?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Need to find a solution similar to Yahoo News related search





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC