vb.net - how to use id of a button in if statement using javascript -
i beginner javascript , trying perform arithmetic functions.
here code below:
script
<script language="javascript" type="text/javascript"> function func(a,b) { var = document.getelementbyid("a"); var b = document.getelementbyid("b"); if (document.getelementbyid("btnadd").text == 'add') { var c = + b; document.getelementbyid("rslt").innerhtml =c; } } </script>
aspx
<asp:button id="btnadd" text="add" runat="server" onclientclick="func(txtn1,txtn2)" /> <p id="rslt"></p>
my idea is, when click 'add' button value of 2 textbox should passed script , assigned 2 variables.
with 2 variables arithmetic (add,sub,div,mul) should done.
what pass button clicked, using this
. way know text of button clicked. , since using server side button, sure include return false;
javascript call prevent posting , clearing <p>
tag.
<asp:button id="btnadd" runat="server" text="add" onclientclick="func('txtn1', 'txtn2', this); return false;" />
function func(a, b, btn) { var txtn1 = document.getelementbyid(a); var txtn2 = document.getelementbyid(b); var rslt = document.getelementbyid('rslt'); if(btn.value == 'add') rslt.innerhtml = parseint(txtn1.value) + parseint(txtn2.value); }
Comments
Post a Comment