Solved

simple java script problem

Posted on 2010-09-23
17
404 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS - Centering an image 2 23
CSS for <center> 14 31
How to get chosen background-color on every line? 10 14
title attribute 5 22
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

685 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