Labels

Monday, June 28, 2010

Javascript: Inline javascript function in event handler declaration

If you want to write javascript function code directly in the onclick event handler declaration instead of using a separate function for that code, you can do it as follows:

<input type="button" value="Save" onclick="javascript:(function(){ //your code; })();"/>

2 comments:

Unknown said...

Hey Prashant,
Very useful code for calling very small function directly.

Unknown said...

Hi Prashant,

Really very helpful for calling javascript function with one or two line. No need to make a function outside.

Great work...

Post a Comment