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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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[ 'txtTotalP rice'].val ue = document.forms['calcform'] .elements[ 'txtQuan'] .value * document.forms['calcform'] .elements[ 'txtUnitPr ice'].valu e;
return true;
}
</SCRIPT>
.
.
.
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']
return true;
}
</SCRIPT>
.
.
.
ASKER
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('t xtTotalPri ce').value = document.getElementById('t xtUnitPric e ').value x document.getElementById('t xtQuan ').value
}
{
document.getElementById('t
}
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']
ASKER
darkyin87:
it does not like the X in you code. it says it expects ;
it does not like the X in you code. it says it expects ;
For multiplication it should be * (asterisk) not X.
ASKER
Can i call it like this?
OnChange="calcTotal()"
OnChange="calcTotal()"
ASKER
OnChange='calcTotal()' did not work
ASKER
This is what i am doing
<telerik:RadNumericTextBox ID="txtQuantity" TextChanged="calcTotal()" runat="server" Width="30px"
</telerik:RadNumericTextBo x></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
<telerik:RadNumericTextBox
</telerik:RadNumericTextBo
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 (").
ASKER
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('t xtQuantity ').TextCha nged = calcTotal;
eg:
<BODY onload="document.getElemen tById('txt Quantity') .TextChang ed = calcTotal">
document.getElementById('t
eg:
<BODY onload="document.getElemen
ASKER
It is asp.net user control it does not have a <body> tag
ASKER
you both helped so thank you
ASKER