Solved

simple java script problem

Posted on 2010-09-23
17
396 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
Comment Utility
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
Comment Utility
I would use onBlur event n chk whether the value has changed and then calculate the result.
0
 

Author Comment

by:vbnetcoder
Comment Utility
darkyin87: How would i calculate the result?
0
 
LVL 16

Expert Comment

by:jmatix
Comment Utility
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
Comment Utility
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
Comment Utility
function onBlur()
{
document.getElementById('txtTotalPrice').value = document.getElementById('txtUnitPrice ').value x document.getElementById('txtQuan ').value
}
0
 
LVL 16

Expert Comment

by:jmatix
Comment Utility
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
Comment Utility
darkyin87:

it does not like the X in you code. it says it expects ;
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:jmatix
Comment Utility
For multiplication it should be * (asterisk) not X.
0
 

Author Comment

by:vbnetcoder
Comment Utility
Can i call it like this?

OnChange="calcTotal()"
0
 

Author Comment

by:vbnetcoder
Comment Utility
OnChange='calcTotal()' did not work
0
 

Author Comment

by:vbnetcoder
Comment Utility
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
Comment Utility
You can use either single quote (') or double quote (").
0
 

Author Comment

by:vbnetcoder
Comment Utility
Am i calling it wrong?
0
 
LVL 16

Expert Comment

by:jmatix
Comment Utility
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
Comment Utility
It is asp.net user control it does not have a <body> tag
0
 

Author Closing Comment

by:vbnetcoder
Comment Utility
you both helped so thank you
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

8 Experts available now in Live!

Get 1:1 Help Now