Hi Parthasarathi Sarathi,
Sounds like you are on the right track.
Have you exposed your function from a Web Method? this is mandatory if you wish to call it from page code.
Also, you can use the $w api to change the label of your button:
Hope this helps.
Idan.