Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
<input type='button' id="btnGroups1"   önclick="return fnTabChanges('0')"/>
<input type='button' id="btnGroups2"   önclick="return fnTabChanges('1')"/>
<input type='button' id="btnGroups3"   önclick="return fnTabChanges('2')"/>
<input type='button' id="btnGroups4"   önclick="return fnTabChanges('3')"/>

how to write condition in javascript if third button is click. 
if(fnTabChanges()==2)
{
//code
}

is it true...
please help..???
Posted
Updated 24-Nov-19 16:07pm
v3
Comments
Karthik_Mahalingam 24-Dec-13 9:10am    
what you want to return ?

hi try this code..


XML
<script type="text/javascript">

       function fnTabChanges(index) {
           if (index == '2')
           { alert(' third button clicked'); }
       }

   </script>
 
Share this answer
 
Comments
Peter Leow 27-Dec-13 1:52am    
Do not be discouraged. You have answered correctly to the question, +5!.
Karthik_Mahalingam 27-Dec-13 2:10am    
thanks peter
EhabAhmed 31-Aug-19 23:10pm    
Thanks +5
Try the following and adapt it if it suits your need:

<html>
<body>
<input type='button' id="button1" value='first button' onclick="clickMe(this)"/>
<input type='button' id="button2" value='second button' onclick="clickMe(this)"/>
<input type='button' id="button3" value='third button' onclick="clickMe(this)"/>
<input type='button' id="button4" value='fourth button' onclick="clickMe(this)"/>
 
<script>
function clickMe(e){
 
    alert("You have clicked button id = "+e.id+" and button value = "+document.getElementById(e.id).value);
 
}
</script>
 
</body>
</html>
 
Share this answer
 
v3
You can return the value as follows

C#
function fnTabChanges(index) {
           //Some condition and code here as per logic
return someValue;
       }


Now to retrieve the value
önclick="var result = fnTabChanges('0');alert(result);"


// variable result has the return value , alert(result); is added to testing purpose

Hope this helps...
 
Share this answer
 
<input type='button'  value = '1' id="btnGroups1"   önclick="return fnTabChanges(this.value)"/>


try it, I hope it can help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900