|
 |
|
อยากเอาตัวเลขใน Text box มาคูณกัน จะเขียนโค้ดอย่างไรดีครับผม |
|
 |
|
|
 |
 |
|
function calculate(id1,id2,id3)
{
var value1 = parseFloat(document.getElementById(id1).value);
var value2 = parseFloat(document.getElementById(id2).value);
var value3 = "";
if(value1 && value2){
value3 = value1*value2;
}
document.getElementById(id3).value = value3;
}
</script>
<input name="text1" onkeyup="calculate('text1','text2','text3');" onKeyPress="if(event.keyCode>=48 && event.keyCode<=57){}else{event.returnValue = false;}"/>
<input name="text2" onkeyup="calculate('text1','text2','text3');" onKeyPress="if(event.keyCode>=48 && event.keyCode<=57){}else{event.returnValue = false;}"/>
<input name="text3" readonly="" />
|
 |
 |
 |
 |
Date :
2011-04-25 15:03:29 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ครับผมเอาโค้ดของพี่ไปใส่ดูแล้ว แบบข้างล่างนี้นะครับพี่ พอรันดูไม่ได้นะครับพี่ พอใส่ตัวเลขเข้าไป Error เลยครับผม
<!--
Quantity
-->
<tr>
<td align="right">Quantity</td>
<td> </td>
<td>
<input type="text" id="txtQuantity" name="txtQuantity" style="width:300px;" class="txt" onkeypress="txtQuantity_KeyPress(event)";
onkeyup="txtCalculate_KeyPress(txtQuantity,txtUnitPrice,txtAmount)"; onKeyPress="if(event.keyCode>=48 && event.keyCode<=57){}else{event.returnValue = false;}"/>
</td>
</tr>
<!--
Unit Price
-->
<tr>
<td align="right">Unit Price</td>
<td> </td>
<td>
<input type="text" id="txtUnitPrice" name="txtUnitPrice" style="width:300px;" class="txt" onkeypress="txtUnitPrice_KeyPress(event)";
onkeyup="txtCalculate_KeyPress(txtQuantity,txtUnitPrice,txtAmount)"; onKeyPress="if(event.keyCode>=48 && event.keyCode<=57){}else{event.returnValue = false;}"/>
</td>
</tr>
<!--
Amount
-->
<tr>
<td align="right">Amount</td>
<td> </td>
<td>
<input type="text" id="txtAmount" name="txtAmount" value="" style="width:300px; text-align:left;" class="txt" readonly="" />
</td>
</tr>
<script>
function txtCalculate_KeyPress(txtQuantity,txtUnitPrice,txtAmount){
var txtQuantity = parseFloat(document.getElementById(txtQuantity).value);
var txtUnitPrice = parseFloat(document.getElementById(txtUnitPrice).value);
var txtAmount = "";
if(txtQuantity && txtUnitPrice){
txtAmount = txtQuantity * txtUnitPrice;
}
document.getElementById(txtAmount).value = txtAmount;
}
</script>
|
 |
 |
 |
 |
Date :
2011-04-25 15:36:58 |
By :
Supot L |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับพี่ ขอบพระคุณมากครับผม
|
 |
 |
 |
 |
Date :
2011-04-25 16:03:43 |
By :
Supot L |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|