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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with form calculator

    Hello guys,
    long story short my boss wants me to add this calculator form to our website(here is the link to what he wants exactly) so I try to copy that code but it won't work. I was wondering if this javascript would work.

    Code:
    Code:
    <script language="JavaScript">
    function calc() {
    gear = document.name1.drpPumpType.1;
    vane = document.name1.drpPumpType.2;
    
    if (gear)
    {
    
    txtW = document.form1.txtW.value;
    txtD = document.form1.txtD.value;
    txtL = document.form1.txtL.value;
    int gearCIR;
    gearCIR = 6 * txtW *(2 * txtD - txtL) * (txtL - txtD) / 2;
    }
    else
    {
    int vaneCIR;
    vaneCIR = 12 * txtW * (txtL + txtD) / 4 * (txtL - txtD) / 2;
    }
    I probably don't even need a if statement but I haven't program in a long time and never use java script before. so bare with me.

    here is the html form code
    Code:
    Code:
    <form name="name1">
    <table align="center" border="0" width="44%">
    <tbody>
    <tr>
    <td colspan="3"><span class="BoldHeadingLabel style1">Displacement&nbsp;from&nbsp;Measurements</span></td></tr>
    <tr>
    <td width="50"><span class="style1"></span><br />
    </td>
    <td width="157"><span class="BoldLabel style1">Pump/Motor&nbsp;Type:</span></td>
    <td width="456"> <span class="style1"></span> <br />
    </td></tr>
    <tr>
    <td width="50"><span class="style1"></span><br />
    </td>
    <td width="157"><span class="BoldLabel style1">Gear&nbsp;Width&nbsp;(W):</span></td>
    <td><span class="style1"><input name="txtW" id="txtW" maxlength="10" size="10" value="" type="text" /></span></td></tr>
    <tr>
    <td width="50"><span class="style1"></span><br />
    </td>
    <td width="157"><span class="BoldLabel style1">Gear&nbsp;Bore&nbsp;Dia.&nbsp;(D):</span></td>
    <td><span class="style1"><input name="txtD" id="txtD" maxlength="10" size="10" value="" type="text" /></span></td></tr>
    <tr>
    <td width="50"><span class="style1"></span><br />
    </td>
    <td width="157"><span class="BoldLabel style1">Bore&nbsp;to&nbsp;Bore&nbsp;(L):</span></td>
    <td><span class="style1"><input name="txtL" id="txtL" maxlength="10" size="10" value="" type="text" /></span></td></tr>
    <tr>
    <td colspan="3"><span class="style1"></span><br />
    </td></tr>
    <tr>
    <td width="50"><span class="style1"></span><br />
    </td>
    <td width="157"><span class="BoldLabel style1">Displacement&nbsp;(CIR)&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;</span></td>
    <td><span class="CalAnswer style1">_________</span><span class="style1"><br />
    </span></td></tr>
    <tr></tr>
    <tr>
    <td colspan="3"><span class="style1"></span><br />
    </td></tr>
    <tr>
    <td colspan="3" align="center"><input value="Calculate" id="submit1" name="submit1" type="submit" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value="Clear" id="clearform" name="clearform" onclick="cmdReset_onclick()" type="button" /> </td></tr></tbody></table></form>
    For some reason it says access denied. I copy this code from that website. but can't find any code wrong.
    I know this code is probably so wrong but any help is much appreciated .
    Last edited by jdgrinder; 12-09-2011 at 07:48 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    No, you didn't copy that code off of that web site. That web site does the calculation in ASP code, on the server.

    And in any case, you don't have any way there to select whether the pump is gear or valve type.

    The page you showed uses a <select>. (Which is kind of silly...with only two choices, I'd just use a pair of radio buttons.) You have nothing.

    Aside from that, there are 3 major mistakes in your JavaScript code, but there is not point in fixing them until you fix the HTML.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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