Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

simple java script problem

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.
ASKER CERTIFIED SOLUTION
Avatar of Justin Mathews
Justin Mathews

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbnetcoder
vbnetcoder

ASKER

darkyin87: How would i calculate the result?
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>
.
.
.
My form happens to be a asp.net user control. do you know what i would put in for form name?
function onBlur()
{
document.getElementById('txtTotalPrice').value = document.getElementById('txtUnitPrice ').value x document.getElementById('txtQuan ').value
}
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']
darkyin87:

it does not like the X in you code. it says it expects ;
For multiplication it should be * (asterisk) not X.
Can i call it like this?

OnChange="calcTotal()"
OnChange='calcTotal()' did not work
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
You can use either single quote (') or double quote (").
Am i calling it wrong?
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">
It is asp.net user control it does not have a <body> tag
you both helped so thank you