Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Alternate Inputs for a Form

    Hi-- I'm writing a Java Script calculator for winemakers that will calculate required additions to the grape juice based upon the quantity of juice entered, the current amount of a chemical called SO2 and the desired amount of SO2. The problem I'm having is with the quantities-- I'm trying to write this such that it'll work with either gallons or liters. In the quantity function, I'm able to convert from one to the other, i.e. if gallons are blank it's calculated from the liters entered and vice versa. But the other functions, validate and calculate seem to ignore the caluculated values. I program was originally writtedn for gallons only and if the liters pieces are stripped out, everything works. It's as if the other functions run before the calculations can occur. Below is the whole of the code, inclusive of the form. Any help would be greatly appreciated-- I've run out of ideas. Thanks in advance.


    <html>
    <head>

    <title>Sulfite</title>
    <script language="JavaScript">


    function quantity(input) {
    gallons=input.gallons.value;
    liters=input.liters.value;
    if (gallons == "")
    input.gallons.value=(liters*.26);

    if (liters == "")
    input.liters.value=(gallons*3.79);
    currentso2=input.currentso2.value;
    desiredso2=input.desiredso2.value;
    validate(input)

    }

    function validate(input) {

    if (gallons == "")
    window.alert("Please enter the quantity of must, juice or wine");
    if (liters == "")
    window.alert("Please enter the quanitity of must, juice or wine");
    if (currentso2 == "")
    window.alert("Please enter the current sulfite level in the must, juice or wine");
    if (desiredso2 == "")
    window.alert("Please enter the desired sulfite level in the must, juice or wine");

    if (desiredso2 < 50)
    window.alert("To mimimize the chance of spoilage and oxidation, at least 50ppm of Sulfur Dioxide is recommended");
    if (desiredso2 > 150)
    window.alert("Sulfur Dioxide levels greater than 150ppm can impact the taste of your finished wine and lead to adverse reactions in some people");
    if (currentso2 > desiredso2)
    window.alert("Your current free sulfite level you entered is greater than the desired sulfite level you entered. If this is correct, you do not need to add any additional sulfite");
    calculate(results)
    }



    function calculate(results) {

    so2grams=((desiredso2-currentso2)*(gallons/150));
    so2gramsround=Math.round(so2grams);
    so2tsps=(so2grams/6.2);
    so2tspsfull=Math.floor(so2tsps);
    so2tspsdec=(so2tsps-so2tspsfull);
    campden=((desiredso2-currentso2)*(gallons/75));
    campdenfull=Math.floor(campden);
    campdendec=(campden-campdenfull);


    if (so2gramsround >0)
    results.so2gramsround.value=so2gramsround;
    else
    results.so2gramsround.value=0;

    if (so2tspsfull <1)
    so2tspsfull=""

    if (so2tspsdec >.9)
    results.so2tspsfraction.value=so2tspsfull+1;
    else if (so2tspsdec >.65)
    results.so2tspsfraction.value=so2tspsfull+" 3/4";
    else if (so2tspsdec >.4)
    results.so2tspsfraction.value=so2tspsfull+" 1/2";
    else if (so2tspsdec >.2)
    results.so2tspsfraction.value=so2tspsfull+" 1/4";
    else if (so2tspsdec >.1)
    results.so2tspsfraction.value=so2tspsfull+" 1/8";
    else
    results.so2tspsfraction.value=so2tspsfull;
    if (so2gramsround <1)
    results.so2tspsfraction.value=0;

    if (campdendec >.75)
    results.campdenfraction.value=campdenfull+1;
    else if (campdendec >.25)
    results.campdenfraction.value=campdenfull+" 1/2";
    else
    results.campdenfraction.value=campdenfull;

    if (campdenfull <1)
    campdenfull="0"


    }

    </script>
    </head>
    <br>
    <div align="left"><form name=input>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="101%" id="AutoNumber1" height="161">
    <tr>
    <td width="73%" height="1"><b><font face="Verdana" size="4">Information
    Required</font></b></td>
    <td width="7%" height="1"> </td>
    <td width="111%" colspan="3" height="1"></td>
    </tr>
    <tr>
    <td width="73%" height="1"><font size="2" face="Verdana">Please enter
    your quantity of must or juice in Gallons </font> </td>
    <td width="7%" height="1">
    <input type=text name=gallons size=5 style="font-family: Verdana; text-align: center"></td>
    <td width="111%" colspan="3" height="1"><font face="Verdana" size="2"> or
    in liters </font>
    <input type=text name=liters size=5 style="font-family: Verdana; text-align: center"></td>
    </tr>
    <tr>
    <td width="73%" height="22"><font face="Verdana" size="2">Please enter the current quantity of free sulfites in your must, juice or wine </font></td>
    <td width="7%" height="22">
    <input type=text name=currentso2 size=5 style="font-family: Verdana; text-align: center"></td>
    <td width="111%" colspan="3" height="22"><font face="Verdana" size="2"> in parts per million</font></td>
    </tr>
    <tr>
    <td width="73%" height="22"><font face="Verdana" size="2">Please enter the desired
    quantity of free sulfites in your must, juice or wine</font></td>
    <td width="7%" height="22">
    <input type=text name=desiredso2 size=5 style="font-family: Verdana; text-align: center"></td>
    <td width="111%" colspan="3" height="22"><font face="Verdana" size="2"> in
    parts per million</font></td>
    </tr>
    <tr>
    <td width="73%" height="18"></td>
    <td width="7%" height="18"> </td>
    <td width="9%" height="18"></td>
    <td width="13%" height="18"> </td>
    <td width="92%" height="18"></td>
    </tr>
    <tr>
    <td width="73%" height="15"></td>
    <td width="16%" height="15" colspan="2" align="right"> <font face="Verdana">
    <input type=button value="Calculate" onclick="quantity(form)" style="text-align: center"></font></td>
    <td width="13%" height="15" align="center"> <font face="Arial"> <input type=reset value="Reset"></font></td>
    <td width="92%" height="15"></td>
    </tr>
    <tr>
    <td width="66%" height="22" colspan="3"> </td>
    <td width="13%" height="22"> </td>
    <td width="92%" height="22"> </td>
    </tr>
    </table></form>
    <form name=results>
    <font face="Verdana"><b><font size="4">Recommended Sulfite Additions</font></b><br>
    </font><font face="Verdana" size="2">• </font> <font face="Verdana">
    <font size="2">To achieve your desired level of free sulfites, the recommended
    amount of potassium metabisulfite to be added to your must, juice or wine is
    </font>
    <input type=text name=so2gramsround size=5 style="font-family: Verdana; font-weight: bold; text-align: center; border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1"><font size="2">
    grams which is approximately </font>
    <input type=text name=so2tspsfraction size=6 style="font-family: Verdana; font-weight: bold; text-align: center; border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1"><font size="2"> teaspoons.

    </font></font></p>
    <p><font face="Verdana" size="2">• </font> <font face="Verdana"><font size="2">Alternatively, the addition of
    </font>
    <input type=text name=campdenfraction size=6 style="font-family: Verdana; font-weight: bold; text-align: center; border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1"><font size="2"> Campden tablets will also bring your must, juice or wine to the free sulfite level you specified. </font></font></p>
    </form></div>



    </body>
    </html>

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please do not double post your questions:
    Alternative Input for Forms

    Additionally, it would be to your benifit to read the forum posting guidelines, particularly those regarding using bbCode [code] ...CODE HERE... [/code] when posting code... That is an awful lot of code for someone to cut from your post and this may very well be the reason noone has responded... But still, a lack of response is not a reason to double post...

    .....Willy
    Last edited by Willy Duitt; 12-05-2004 at 09:01 PM.

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, actually the double post was an accident. But in the interim, I've figured out the problem-- my function was establishing the calculated quantities as a value for the form but not as a variable. Thanks to all that took a look at this, I'm good to go now.

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Did I waste 30 minutes of my time in the other thread?

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Yes, but he did thank you in advance.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •