i wanna make simple script that multiply any input by .51 and show the result automatic, without pressing any button,i got two scripts first script add value one to value two and show result auto, other script multiply but i have to press button, how to merge them :S
and if there are script do the job better than those tell me :)
Target: Input Box, when i input any value the result of multiply that value by .51 appear beside it automatic :)
Script One:
</head>
<script type="text/javascript" language="javascript">
function autocalc(oText)
{
if (isNaN(oText.value)) //filter input
{
alert('Numbers only!');
oText.value = '';
}
var field, val, oForm = oText.form, total = a = 0;
for (a; a < arguments.length; ++a) //loop through text elements
{
field = arguments[a];
val = parseFloat(field.value); //get value
if (!isNaN(val)) //number?
{
total += val; //accumulate
}
}
oForm.total.value = total; //out
}
</script>
</head>
<body onload="document.forms[0].reset()">
<form style="width:260px;margin:100px auto;border:2px black dashed;">
<table cellspacing="8">
<tr>
<!-- pass field reference ('this') and other field references -->
<td>value 1___<input name="t1" type="text" onkeyup="return autocalc(this,t2)" tabindex="1"></td>
<td rowspan="3"><strong>total_____</strong><input name="total" type="text" readonly="readonly" value="0" tabindex="-1"></td>
</tr><tr>
<td>value 2___<input name="t2" type="text" onkeyup="return autocalc(this,t1)" tabindex="2"></td>
</tr>
</table>
</form>
</body>
Code Two:
<head>
<script language="JavaScript">
<!-- Begin
function doMath() {
var one = eval(document.theForm.elements[0].value)
var two = eval(document.theForm.elements[1].value)
var prod = one * two
alert("The product of " + one + " and " +
two + " is " + prod + ".")
}
// End -->
</script>
</head>
<body>
<center>
<form name="theForm">
Multiply
<input type="text">
By
<input type="text">
<input type="button" value="Show result" onClick="doMath()">
</form>
</center>
</body>