Forum Moderators: open
var re = substr("cd"+c, -4); <html>
<head>
<script type="text/javascript">
function getCdCost( )
{
var re = substr("cd"+c, -4);
var form = document.selectionForm;
var count = 0;
for ( var c = 1; c < 9999; ++c )
{
var fld = form.elements["cd"+c];
if ( fld == null ) break; // out of loop when no more
var val = fld.value.replace(/\s/g,""); // zap spaces
if ( val != "" )
{
if ( re.test( val ) ) ++count;
} else {
alert( "Invalid L number: " + fld.value );
}
}
var cost = 0;
if ( count > 0 ) cost = 23 + 6 * ( count - 1 );
}
</script>
</head>
<body>
<form method="POST" name="selectionForm" action="sendform.php">
<input type="text" name="cd1" size="3" maxlength="5" onchange="getCdCost();this.form.SUBMIT.focus();"><br/>
<input type="text" name="cd2" size="3" maxlength="5" onchange="getCdCost();this.form.SUBMIT.focus();"><br/>
<input type="text" name="cd3" size="3" maxlength="5" onchange="getCdCost();this.form.SUBMIT.focus();"><br/>
<input type="text" name="cd4" size="3" maxlength="5" onchange="getCdCost();this.form.SUBMIT.focus();"><br/>
<br/>
<input type="text" name="total" readonly>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>