p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > Visual Web Developer 2005
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 5th, 2007, 03:16 PM
Authorized User
 
Join Date: Jun 2007
Location: monroe, newjersey, USA.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 5th, 2007, 04:03 PM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old June 21st, 2009, 11: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);
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 07:48 PM
Add textbox in cs file khorshid_sh ASP.NET 1.0 and 1.1 Basics 2 April 30th, 2008 03:37 PM
Javascript changes to Textbox Control wyokid ASP.NET 1.0 and 1.1 Professional 2 June 28th, 2006 02: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



All times are GMT -4. The time now is 03:23 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc