Click to See Complete Forum and Search --> : Need help finishing JS


donald d
04-23-2003, 03:29 PM
This may be simple to mostly everyone out there but i am an entry JS programmer. I have created 95% of this script but i need to add the following:

If the number to order is greater than 0, write the number that needs to be ordered, if not write a message saying no order needed.

thanks
DD

AdamBrill
04-23-2003, 04:00 PM
Is this what you wanted?<HTML>
<HEAD>
<TITLE>AVEFUNC INVENTORY</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function calcAvg(inventory)
{
onhand = document.inventory.onhand.value;
onorder = document.inventory.onorder.value;
reorderpt = document.inventory.reorderpt.value;
numorder = (onhand - onorder - reorderpt);
document.inventory.numorder.value=numorder;
if(numorder>0){
alert("The number to order is " + numorder);
}else{
alert("No order needed");
}
}
function clearData(inventory)
{
document.inventory.onhand.value = "";
document.inventory.onorder.value = "";
document.inventory.reorderpt.value = " ";
document.inventory.numorder.value = " ";
}
</SCRIPT>
</HEAD>
<BODY bgcolor=#99CCFF text="#000000">
<H1>Calculate number to order</H1>
<H3>Enter the following information and then press the <B>AVERAGE</B> button to calculate
your grade.</H3>
<H3>To clear the data fields, press the <B>CLEAR</B> button.
<FORM NAME="inventory">
Enter On Hand:
<INPUT TYPE="text" NAME="onhand" SIZE=4><BR>
Enter On Order:
<INPUT TYPE="text" NAME="onorder" SIZE=4><BR>
Enter Reorder Point:
<INPUT TYPE="text" NAME="reorderpt" SIZE=4><BR><BR>
<INPUT TYPE="button" VALUE="Number to order" onClick="calcAvg(inventory)">
<INPUT TYPE="button" VALUE="CLEAR" onClick="clearData(inventory)">
<BR><BR>
The Number to order is:
<INPUT TYPE="text" NAME="numorder" SIZE=4><BR>
</FORM>
</BODY>
</HTML>Let me know if that isn't what you wanted... ;)