How to call button from page activity in script to verify which button clicked ? | Community
Skip to main content
Prasanna_Soni
Level 4
April 30, 2021
Solved

How to call button from page activity in script to verify which button clicked ?

  • April 30, 2021
  • 2 replies
  • 1127 views

I have page with 2 buttons based on click of button i have to perform certain task. in Java script i need help to decide on the same, so its very importnat for me to read the button id . I assume it will be something like ctx.buuton_id.click() = True or something similar but dont know and hence need guidence . 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Amit_Shinde

Hi @prasanna_soni,

 

Sharing sample code. Please try the below logic.


<html>
<head>
<script>
function myFunction(selectedButton){
if(selectedButton=="Button1")
{
// Add javascript Code & 1st transition
document.controller.submit("next", "", "next"); ;
}
if(selectedButton=="Button2")
{
// Add javascript code & 2nd transition
document.controller.submit("next", "", "next2"); ;
}

}
</script>
</head>
<body style="" class="">
<form>
<p>Please click the button</p>
<div class="submit-field"><span>&gt;</span><button id="Button1" onclick="return myFunction(this.value)" value="Button1">Button1</button></div>
<div class="submit-field"><span>&gt;</span><button id="Button2" onclick="return myFunction(this.value)" value="Button2">Button2</button></div>
</form>
</body>
</html>

 

Thanks,

Amit

2 replies

Amit_ShindeAccepted solution
Level 3
May 1, 2021

Hi @prasanna_soni,

 

Sharing sample code. Please try the below logic.


<html>
<head>
<script>
function myFunction(selectedButton){
if(selectedButton=="Button1")
{
// Add javascript Code & 1st transition
document.controller.submit("next", "", "next"); ;
}
if(selectedButton=="Button2")
{
// Add javascript code & 2nd transition
document.controller.submit("next", "", "next2"); ;
}

}
</script>
</head>
<body style="" class="">
<form>
<p>Please click the button</p>
<div class="submit-field"><span>&gt;</span><button id="Button1" onclick="return myFunction(this.value)" value="Button1">Button1</button></div>
<div class="submit-field"><span>&gt;</span><button id="Button2" onclick="return myFunction(this.value)" value="Button2">Button2</button></div>
</form>
</body>
</html>

 

Thanks,

Amit

Sukrity_Wadhwa
Community Manager
Community Manager
May 17, 2021

Hi @prasanna_soni,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know.

Thanks!

Sukrity Wadhwa