/    Sign up×
Community /Pin to ProfileBookmark

How to get the result from javascript to asp.net

I am trying to add two numbers entered in a text box with javascript call and return that to a third text box. Could any one suggest, how to show the result in third text box.
My code is

[Code]
<SCRIPT language=”JavaScript”>
function checkValue(tbox1, tbox2)
<!–
{
var tot
tot = textbox1 + textbox2;
return tot
}

//–>
</SCRIPT>

<asp:datagrid id=”MyDataGrid” runat=”server” AutoGenerateColumns=”false”>
<Columns>
<asp:TemplateColumn HeaderText=”Rent per Sq Feet”>
<ItemTemplate>
<asp:TextBox ID=”TxtRent” Runat=”server” ></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=”Area” HeaderStyle-Width=”10%”>
<ItemTemplate>
<asp:TextBox ID=”TxtArea” Runat=”server” OnTextChanged=”CallFun” Text=”..” AutoPostBack=True ></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=”Total” HeaderStyle-Width=”10%”>
<ItemTemplate>
<asp:TextBox ID=”TxtTot” Runat=”server” ></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
[/Code]

Code Behind

[Code]
Sub CallFun(ByVal sender As Object, ByVal e As EventArgs)
Dim TxtAreaInSqFeet As TextBox = sender
Dim dgItem As DataGridItem = TxtAreaInSqFeet.Parent.Parent
Dim t1 As TextBox = dgItem.FindControl(“TxtRent”)
Dim t2 As TextBox = dgItem.FindControl(“TxtArea”)
Dim t3 As TextBox = dgItem.FindControl(“TxtTot”)
t3.Attributes.Add(“onblur”, “return checkValue(‘” & t1.Text & “‘,'” & t2.Text & “‘);”)

End Sub
[/Code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 18.2006 — This:
[code=html]<SCRIPT language="JavaScript">
function checkValue(tbox1, tbox2)
<!--
{
var tot
tot = textbox1 + textbox2;
return tot
}

//-->
</SCRIPT>[/code]

should be more like this:
[code=html]<script type="text/javascript">
<!--//
function checkValue(tbox1, tbox2)
{
return (Number(tbox1.value) + Number(tbox2.value));
}
//-->
</script>[/code]
Copy linkTweet thisAlerts:
@ceemaauthorJun 19.2006 — Hello,

Actually I have solved this problem yesterday like this...

t3.Attributes.Add("onblur", "return checkValue(this, '" & t1.ClientID& "','" & t2.ClientID& "');")

<SCRIPT language="JavaScript">

function checkValue(thisTxt, tbox1Id, tbox2Id)

<!--

{

var txt1Obj = document.getElementById(tbox1Id);

var txt2Obj = document.getElementById(tbox2Id);

thisTxt.value = txt1Obj.value + txt2Obj.value;

}

//-->
</SCRIPT>


But now my problem is this..

I am getting this value only after second trial of onblur of the textbox3. Anyway to solve this issue?

Thanks

Ceema
×

Success!

Help @ceema spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...