Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > Visual Web Developer 2005
|
Visual Web Developer 2005 Discuss creating ASP.NET 2.0 sites with Microsoft's Visual Web Developer 2005. If your question is more specific to a piece of code than the Visual tool, see the ASP.NEt 2.0 forums instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2007, 02:16 PM
Authorized User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to preetham.sarojavenkatesh
Default how to add two textbox value in javascript

hai,
Its very urgent.can somebody tell m,how to add two textboxes and then display the result in the third textbox ,using keypress -in javascript....
regards....

preet
__________________
preet
 
Old October 5th, 2007, 03:03 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm you could something like this
<script language="javascript">
function AppendValues(form)
{
var TextBox1 = form.textbox1.value;
var TextBox2 = form.textbox2.value;
form.textbox3.value = Textbox1 + TextBox2;
}
</script>

<INPUT type = text name="textbox1" onChange="AppendValues(this.form);">
<INPUT type = text name="textbox2" onChange="AppendValues(this.form);">
<INPUT type = text name="textbox3" READONLY>

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
 
Old June 21st, 2009, 10:36 PM
Registered User
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chk it out

Quote:
Originally Posted by preetham.sarojavenkatesh View Post
hai,
Its very urgent.can somebody tell m,how to add two textboxes and then display the result in the third textbox ,using keypress -in javascript....
regards....

preet
This will work for you

You would need to handle the server-side RowDataBound event of the Grid and attach the event handler there.

aspx file:

<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Some value">
<ItemTemplate>
<asp:TextBox ID="gridTextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Some value">
<ItemTemplate>
<asp:TextBox ID="gridTextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Some value">
<ItemTemplate>
<asp:TextBox ID="gridTextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<script type="text/javascript">
<!--
function gridTextBoxOnBlur(textBox1Id, textBox2Id, textBox3Id)
{
var textBox1Ref = document.getElementById(textBox1Id);
var textBox2Ref = document.getElementById(textBox2Id);
var textBox3Ref = document.getElementById(textBox3Id);

// Clear the totals TextBox...
textBox3Ref.value = '';

var textBox1Value = textBox1Ref.value;
var textBox2Value = textBox2Ref.value;

// Check for content...
if ( textBox1Value.length <= 0 )
{
alert('Please enter a value in TextBox #1');
textBox1Ref.focus();
textBox1Ref.select();
return false;
}
if ( textBox2Value.length <= 0 )
{
alert('Please enter a value in TextBox #2');
textBox2Ref.focus();
textBox2Ref.select();
return false;
}

// Convert to nemeric...
textBox1Value = parseFloat(textBox1Value);
textBox2Value = parseFloat(textBox2Value);

// Check for numeric content...
if ( isNaN(textBox1Value) == true )
{
alert('The TextBox #1 value is not numeric');
textBox1Ref.focus();
textBox1Ref.select();
return false;
}
if ( isNaN(textBox2Value) == true )
{
alert('The TextBox #2 value is not numeric');
textBox2Ref.focus();
textBox2Ref.select();
return false;
}

// Fille the totals TextBox...
textBox3Ref.value = textBox1Value + textBox2Value;

return true;
}
// -->
</script>

aspx.cs file:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox gridTextBox1 = (TextBox)e.Row.FindControl("gridTextBox1");
TextBox gridTextBox2 = (TextBox)e.Row.FindControl("gridTextBox2");
TextBox gridTextBox3 = (TextBox)e.Row.FindControl("gridTextBox3");
if ( (gridTextBox1 != null) && (gridTextBox2 != null) && (gridTextBox3 != null) )
{
string eventHandler = string.Format("gridTextBoxOnBlur('{0}', '{1}', '{2}');", gridTextBox1.ClientID, gridTextBox2.ClientID, gridTextBox3.ClientID);
gridTextBox1.Attributes.Add("onblur", eventHandler);
gridTextBox2.Attributes.Add("onblur", eventHandler);
}
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add a variable to the name of a textbox? Lucy Classic ASP Basics 4 September 15th, 2009 06:48 PM
Add textbox in cs file khorshid_sh ASP.NET 1.0 and 1.1 Basics 2 April 30th, 2008 02:37 PM
Javascript changes to Textbox Control wyokid ASP.NET 1.0 and 1.1 Professional 2 June 28th, 2006 01:14 PM
Add new record to databased based on textbox input CarolMorgan Classic ASP Professional 2 January 10th, 2005 01:45 PM
add multiple list to textbox stoneman Access 1 November 3rd, 2003 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.