Originally posted by printline
show value of textfield
Collapse
X
-
Yes, onchange won't fire because the field is readonly and hasn't been changed by the user when they remove focus. The simple solution is to add one extra line to the script which changes the value of the first to also change the value of the second total field. -
Hi Mr. Printline, this is a sample codeOriginally posted by printlineHi'
Could you give me an example on how to do this...???
[HTML]<html>
<head>
<script type="text/javascript">
function calculateMe()
{
var a = document.getEle mentById('myTex t1').value;
var b = document.getEle mentById('myTex t2').value;
var res = a*b;
document.getEle mentById('resTe xt1').value=res ;
document.getEle mentById('resTe xt2').value=doc ument.getElemen tById('resText1 ').value
}
</script>
</head>
<body>
Enter a Number: <input type="text" id="myText1"><b r/>
Enter b Number: <input type="text" id="myText2"><b r/>
<input type="button" value="calculat e" onclick="calcul ateMe()"><br/>
Result: <input type="text" id="resText1">< br/>
Copied: <input type="text" id="resText2">< br/>
</body>
</html>[/HTML]
Still confused, post ur code. I will help u out
Regards
Ramanan KalirajanComment
-
Hello RamananKaliraja n
My code looks like this:
Code:<script type="text/javascript"> function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function KW_getVal(o){ //v1.2 var retVal="0";if (o.type=="select-one") {retVal=(o.selectedIndex==-1)?0:o.options[o.selectedIndex].value;} else if (o.length>1){for (var i=0;i<o.length;i++) if (o[i].checked) retVal=o[i].value; } else if (o.type=="checkbox") {retVal=(o.checked)?o.value:0;} else { retVal=Number(o.value)}return parseFloat(retVal); } function KW_calcForm() { //v1.2 var str="",a=KW_calcForm.arguments; for (var i=3;i<a.length;i++) str+=(a[i].indexOf("#")==-1)?a[i]:KW_getVal(MM_findObj(a[i].substring(1))); t=Math.round(a[1]*eval(str))/a[1];tS=t.toString();if(a[2]>0){tSp=tS.indexOf("."); if(tSp==-1) tS+=".";tSp=tS.indexOf(".");while(tSp!=(tS.length-1-a[2])){tS+="0"; tSp=tS.indexOf(".");}} MM_findObj(a[0]).value=tS; } function printThis7() { document.getElementById('total2').value = document.getElementById('total').value; } </script>
[HTML]<input type="text" onchange="print This7()" value="" name="total" size="10" readonly="reado nly">[/HTML]
And this is how the total is calculated (The onblur event):
[HTML]<input name="quantity" type="text" onchange=" onblur="KW_calc Form('total',10 0,2,'(','(','#q uantity','*','# priceperpiece', ')','+','#shipp ing',')','+','# vat')" value="" size="30" />[/HTML]
Does this makes any sence to you....?
My "function printThis7()" doesn't copy the field.Comment
-
That's because onchange doesn't fire. Try this:
[HTML]<input name="quantity" type="text" onblur="KW_calc Form('total',10 0,2,'(','(','#q uantity','*','# priceperpiece', ')','+','#shipp ing',')','+','# vat'); printThis7();" value="" size="30" />[/HTML]Comment
Comment