create a widget such a that when clicked on button it must pop up alert message?

Tejas16
Tera Contributor

I have tried this functionality in a widget.

HTML Template:

<div>
 Click on Button:
  <button ng-click="fun()">
    Click on me
  </button>
</div>

Client script:

function($scope) {    
    var c = this;        
 $scope.fun=function()
 {
     alert("hello world");
 }
    } 

It works well with above code. But instead of ng-click directive,I used onclick() event but it won't work with it?  

 

 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi,

Below link will helps you on your requirement.

https://community.servicenow.com/community?id=community_question&sys_id=a52e9a061bb01910aefc11751a4bcb34

Opening thread will not be a good thing once your issue got fixed and If my response helped please mark it correct and close the thread so that others get benefit in future.

 

Thanks,

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

4 REPLIES 4

Valmik Patil1
Kilo Sage

Hi Tejas,

Using onClick() will not work if you are writing function in client script

You need to use ng-click only to call function

Please refer below example where you can use onClick() using script tag

<div>
 Click on Button:
  <button onClick="test()">
    Click on me
  </button>
  <script>
    	function test(){
		
		alert("test");
	}
  </script>
</div>

Thanks,

Valmik

Thanks.

Pavankumar_1
Mega Patron

Hi,

Refer below link.

 

https://community.servicenow.com/community?id=community_question&sys_id=a52e9a061bb01910aefc11751a4bcb34

 

Hope it helps!!

Please Mark Correct if applicable, Thanks!! 

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Pavankumar_1
Mega Patron

Hi,

Below link will helps you on your requirement.

https://community.servicenow.com/community?id=community_question&sys_id=a52e9a061bb01910aefc11751a4bcb34

Opening thread will not be a good thing once your issue got fixed and If my response helped please mark it correct and close the thread so that others get benefit in future.

 

Thanks,

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar