I need to test for blank inputs and run a routine "if" the input is
blank. This will be used internally on a LAN to calculate selling price
if the "sell" input is blank and a margin is supplied, and to calculate
a margin if the margin input is blank and the sell price is supplied.
The "cost" is set and will be doled out by the CGI. I've tried checking
for a zero variable length ".length" and couldn't get it to work. It
always fires if you check for -1 even if there is something in the
input, and it never fires if you set it any higher. I'm sure I'm just
doing it wrong. Here's where I'm at:
<html>
<head>
<SCRIPT LANGUAGE="JavaS cript">
<!--HIDE
function doMath( ) {
// var one will be set by the CGI when in use
var one = eval(document.t heForm.
elements[0].value)
var two = eval(document.t heForm.
elements[1].value)
var three = eval(document.t heForm.
elements[2].value)
// Run only if sell input is blank
var margin = ((one / three) * 100)
document.theFor m.elements[1].value = margin
// Run only if sell input is blank
var sell = (one / ((100 - two) / 100))
document.theFor m.elements[2].value = sell
}
//STOP HIDING-->
</SCRIPT>
<BODY><FORM NAME="theForm">
Cost <INPUT TYPE="text"> Margin <INPUT TYPE="text"> Sell <INPUT TYPE="text">
<INPUT TYPE="button" VALUE="Calculat e"
onClick="doMath ( )">
</FORM>
</body>
</html>
Suggestions appreciated. :-)
blank. This will be used internally on a LAN to calculate selling price
if the "sell" input is blank and a margin is supplied, and to calculate
a margin if the margin input is blank and the sell price is supplied.
The "cost" is set and will be doled out by the CGI. I've tried checking
for a zero variable length ".length" and couldn't get it to work. It
always fires if you check for -1 even if there is something in the
input, and it never fires if you set it any higher. I'm sure I'm just
doing it wrong. Here's where I'm at:
<html>
<head>
<SCRIPT LANGUAGE="JavaS cript">
<!--HIDE
function doMath( ) {
// var one will be set by the CGI when in use
var one = eval(document.t heForm.
elements[0].value)
var two = eval(document.t heForm.
elements[1].value)
var three = eval(document.t heForm.
elements[2].value)
// Run only if sell input is blank
var margin = ((one / three) * 100)
document.theFor m.elements[1].value = margin
// Run only if sell input is blank
var sell = (one / ((100 - two) / 100))
document.theFor m.elements[2].value = sell
}
//STOP HIDING-->
</SCRIPT>
<BODY><FORM NAME="theForm">
Cost <INPUT TYPE="text"> Margin <INPUT TYPE="text"> Sell <INPUT TYPE="text">
<INPUT TYPE="button" VALUE="Calculat e"
onClick="doMath ( )">
</FORM>
</body>
</html>
Suggestions appreciated. :-)
Comment