MariusGM
asked on
Simple form calculation within repeated region
Hi, I need to perform a simple multiplication calculation within a form that has repeated rows within it.
I have a basic Javascript script that will multiply, by a fixed value, the value a user enters into a textbox and displays it within a readonly textbox beside it. See code below.
I need to be able to use this script (or something similar) in a repeated table within PHP.
I have a basic Javascript script that will multiply, by a fixed value, the value a user enters into a textbox and displays it within a readonly textbox beside it. See code below.
I need to be able to use this script (or something similar) in a repeated table within PHP.
<html>
<head>
<script language="javascript" src="remote.js"></script>
<script type="text/javascript">
function calc(num)
{
var multiplier = 2; //your number here
var result = 0;
if(isFinite(num))
{
result = num * multiplier;
}
result = result.toFixed(0);
document.myform.result.value = result;
}
</script>
</head>
<body>
<form name="myform">
<input type="text" name="txt1" id="txt1" onkeyup="calc(this.value);"/>
<input type="text" name="result" id="result" readonly="readonly"/>
</form>
</body>
</html>
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.
Forced accept.
Computer101
Community Support Moderator
Computer101
Community Support Moderator
var result = 0;
if(isFinite(num)) {
result = num * multiplier;
}
result = result.toFixed(0);
theForm.elements[res].valu
can be shortened to
theForm.elements[res].valu