Solved

simple java script problem

Posted on 2010-09-23
17
401 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
  • 9
  • 6
  • 2
17 Comments
 
LVL 16

Accepted Solution

by:
jmatix earned 250 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 250 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 16

Expert Comment

by:jmatix
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:jmatix
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:jmatix
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:jmatix
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:jmatix
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

803 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