how to get the javascript function value in textbox?
I 开发者_开发问答am writing a javascript function like this, my problem is I can pass the values (quantity and price ) retrieve amount, print the amount in label and textbox(same values), but label is working and in textbox value after selecting another operation first value is coming.
What is the problem in this code or any modification needed (I am using OnChange
event) and some times it is working with IE browser (but adding the master page doesn't work on any browser)
function Total(Quantity,Price,Amt)
{
var Quan=document.getElementById(Quantity).value;
var Pric=document.getElementById(Price).value;
var tt=document.getElementById('lblTotal').innerHTML;
if(tt=='')
{
tt=0;
}
if(Quan=='')
{
}
else
{
var cc1=document.getElementById(Amt).value;
if(cc1!='')
{
tt=parseFloat(tt)-parseFloat(cc1);
}
document.getElementById(Amt).value=(parseFloat(Quan)*parseFloat(Pric)).toFixed(2);
var cc=document.getElementById(Amt).value;
//document.getElementById(Amt).value=cc.toFixed(2);
document.getElementById('lblTotal').innerHTML = (parseFloat(tt)+parseFloat(cc)).toFixed(2);
document.getElementById('h1').value=document.getElementById('lblTotal').innerHTML;
document.getElementById("<%= TextBox1.ClientID %>").innerText =document.getElementById('lblTotal').innerHTML;
}
Change this line
document.getElementById("<%= TextBox1.ClientID %>").innerText =document.getElementById('lblTotal').innerHTML;
to
document.getElementById("<%= TextBox1.ClientID %>").value =document.getElementById('lblTotal').innerHTML;
精彩评论