Arguments of a function

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Arguments of a function

 
0
  #1
Jun 30th, 2005
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.
"Study the past if you would define the future" - Confucius
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Arguments of a function

 
0
  #2
Jul 1st, 2005
Use double quotes around your string:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. "this is hm's program"
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Arguments of a function

 
0
  #3
Jul 4th, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC