Hi Gokul Krishna,
Unfortunately, this is not possible using the HTML/Javascript snippet widget or using Javascript actions. This can only be achieved developing your own widget. You can find some introduction documentation on that here.
Why do you want to use JavaScript? Maybe your usecase can be done via native Mendix!?
Good luck!