Solved

simple java script problem

Posted on 2010-09-23
17
397 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
 
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
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: 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now