Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

simple java script problem

Posted on 2010-09-23
17
Medium Priority
?
418 Views
Last Modified: 2012-05-10
I do not work to often in java script so i need help with something very simple:

I have to there text boxes:

I need to take txtQuan X  txtUnitPrice = txtTotalPrice

This needs to happen when the txtQuan is changed.
0
Comment
Question by:vbnetcoder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 2
17 Comments
 
LVL 16

Accepted Solution

by:
Justin Mathews earned 1000 total points
ID: 33746860
You need to add an onchange() event handler to the <INPUT> field for txtQuan. To do that:

1. Change your HTML <INPUT> tag for txtQuan to add onchange handler as:
<INPUT name='txtQuan' onchange='calcTotal()'>
2. Define calcTotal() JavaScript function  in your HTML
eg:
<HTML>
<HEAD>
<SCRIPT language='javascript'>
function calcTotal()
{
   
document.forms['<your form name here>'].elements['txtTotalPrice'].value =
}
0
 
LVL 4

Assisted Solution

by:darkyin87
darkyin87 earned 1000 total points
ID: 33746896
I would use onBlur event n chk whether the value has changed and then calculate the result.
0
 

Author Comment

by:vbnetcoder
ID: 33746905
darkyin87: How would i calculate the result?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Expert Comment

by:Justin Mathews
ID: 33746958
Sorry, hit submit too soon.

You need to add an onchange() event handler to the <INPUT> field for txtQuan. To do that:

1. Change your HTML <INPUT> tag for txtQuan to add onchange handler as:
<INPUT name='txtQuan' onchange='calcTotal()'>

2. Define calcTotal() JavaScript function  in your HTML
eg: (Assuming your form element name is 'calcform')
<HTML>
<HEAD>
<SCRIPT language='javascript'>
function calcTotal()
{    
document.forms['calcform'].elements['txtTotalPrice'].value = document.forms['calcform'].elements['txtQuan'].value * document.forms['calcform'].elements['txtUnitPrice'].value;
return true;
}
</SCRIPT>
.
.
.
0
 

Author Comment

by:vbnetcoder
ID: 33746993
My form happens to be a asp.net user control. do you know what i would put in for form name?
0
 
LVL 4

Expert Comment

by:darkyin87
ID: 33747033
function onBlur()
{
document.getElementById('txtTotalPrice').value = document.getElementById('txtUnitPrice ').value x document.getElementById('txtQuan ').value
}
0
 
LVL 16

Expert Comment

by:Justin Mathews
ID: 33747065
If the form is the first form in your HTML (or the only form) you can also say document.forms[0] instead of document.forms['calcform']
0
 

Author Comment

by:vbnetcoder
ID: 33747225
darkyin87:

it does not like the X in you code. it says it expects ;
0
 
LVL 16

Expert Comment

by:Justin Mathews
ID: 33747263
For multiplication it should be * (asterisk) not X.
0
 

Author Comment

by:vbnetcoder
ID: 33747463
Can i call it like this?

OnChange="calcTotal()"
0
 

Author Comment

by:vbnetcoder
ID: 33747474
OnChange='calcTotal()' did not work
0
 

Author Comment

by:vbnetcoder
ID: 33747564
This is what i am doing

<telerik:RadNumericTextBox ID="txtQuantity" TextChanged="calcTotal()" runat="server" Width="30px"                                        
</telerik:RadNumericTextBox></td>

and it does not seem to be calling calc total

I am trying to use the TextChanged event because it is outlined for my control here

http://www.telerik.com/help/aspnet/input/radinput-telerik.webcontrols.radnumerictextbox_members.html
0
 
LVL 16

Expert Comment

by:Justin Mathews
ID: 33747575
You can use either single quote (') or double quote (").
0
 

Author Comment

by:vbnetcoder
ID: 33747589
Am i calling it wrong?
0
 
LVL 16

Expert Comment

by:Justin Mathews
ID: 33747696
If it is a third party control and is scriptable, try something like below in your <BODY onload>:

document.getElementById('txtQuantity').TextChanged = calcTotal;

eg:
<BODY onload="document.getElementById('txtQuantity').TextChanged = calcTotal">
0
 

Author Comment

by:vbnetcoder
ID: 33747729
It is asp.net user control it does not have a <body> tag
0
 

Author Closing Comment

by:vbnetcoder
ID: 33749137
you both helped so thank you
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question