Using a html calculation in a form

  • Profile Image
    jonnyg
    Asked on October 26, 2011 at 01:45 PM

    Hi - i have a form that i want to put a calculator into so that my customers are able to get a quote that is then emailed to them from the form. The code i am using normally works in a website but wont work when put in a form and iframed to the site. Any ideas? The code is

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Email Calculator</title>

    <style type="text/css">

    <!--

    .style1 {

     font-size: 12px;

     font-family: Arial, Helvetica, sans-serif;

    }

    -->

    </style>

    <script language="javascript" type="text/javascript">

    <!--

    var co = new Object;

    function recalc_onclick(ctl) {

      if (true) {

     

    co.XLEW_1_1_1=eeparseFloatTh(document.formc.XLEW_1_1_1.value);calc(co);document.formc.XLEW_1_1_2.value=eeisnumber(co.XLEW_1_1_2)?eedisplayFloat(co.XLEW_1_1_2):co.XLEW_1_1_2;

    };};

     

    var eeisus=0;var eetrue="TRUE";var eefalse="FALSE";var eedec=".";var eeth=",";var eedecreg=new RegExp("\\.","g");var eethreg=new RegExp(",","g");var eecurrencyreg=new RegExp("£","g");var eepercentreg=new RegExp("%","g");

    var eecm1=new Array();function calc(data){var cA1A=data.XLEW_1_1_1;var tmp1=(((cA1A)-(42)));var sumcnt2_sum=0+tmp1;var sumcnt2_cnt=1;var cA1B=(((((cA1A)<=(42)))?("42.00"):(((((cA1A)>(42)))?(((((sumgeneral(0,sumcnt2_sum,sumcnt2_cnt,eecm1))*(0.42)))+(42))):("")))));data.XLEW_1_1_2=cA1B;};

     function myIsNaN(x){return(isNaN(x)||(typeof x=='number'&&!isFinite(x)));};function round(n,nd){if(isFinite(n)&&isFinite(nd)){var sign_n=(n<0)?-1:1;var abs_n=Math.abs(n);var factor=Math.pow(10,nd);return sign_n*Math.round(abs_n*factor)/factor;}else{return NaN;}};function sum2(arr,rt,rb){var sum=0;for(var ii=rt;ii<=rb;ii++){sum+=arr[ii]};return sum};function sum3(arr,rt,ct,rb,cb){var sum=0;for(var ii=rt;ii<=rb;ii++){for(var jj=ct;jj<=cb;jj++){sum+=arr[ii][jj]}};return sum};function sumgeneral(cnt,vsum,vcnt,x){var sum=vsum;for(var ii=0;ii<x.length;ii++){sum+=sum3(x[ii][0],x[ii][1],x[ii][2],x[ii][3],x[ii][4]);};return sum;};var near0RegExp=new RegExp("[.](.*0000000|.*9999999)");function eedisplayFloat(x){if(myIsNaN(x)){return Number.NaN;}else{var str=String(x);if(near0RegExp.test(str)){x=round(x,8);str=String(x);}return str.replace(/\./g,eedec);}};function eeparseFloatTh(str){str=String(str).replace(eethreg,"");str=String(str).replace(eedecreg,".");var res=parseFloat(str);if(isNaN(res)){return 0;}else{return res;}};function eedisplayFloatNDTh(x,nd){if(myIsNaN(x)){return Number.NaN;}else{var res=round(x,nd);if(nd>0){var str=String(res);if(str.indexOf('e')!=-1)return str;if(str.indexOf('E')!=-1)return str;var parts=str.split('.');var res2=eeinsertThousand(parts[0].toString());if(parts.length<2){var decimals=('00000000000000').substring(0,nd);return(res2+eedec+decimals);}else{var decimals=((parts[1]).toString()+'00000000000000').substring(0,nd);return(res2+eedec+decimals);}}else{return(eeinsertThousand(res.toString()));}}};

     function eeinsertThousand(whole){if(whole==""||whole.indexOf("e")>=0){return whole;}else{var minus_sign="";if(whole.charAt(0)=="-"){minus_sign="-";whole=whole.substring(1);};var res="";var str_length=whole.length-1;for(var ii=0;ii<=str_length;ii++){if(ii>0&&ii%3==0){res=eeth+res;};res=whole.charAt(str_length-ii)+res;};return minus_sign+res;}};function eeisstring(v){switch(typeof v){case "string":return true;case "object":return v.constructor==String;default:return false;}};function eeisnumber(v){if(isNaN(v)||v==Number.NEGATIVE_INFINITY||v==Number.POSITIVE_INFINITY){return false;}else{switch(typeof v){case "number":return true;case "object":return v.constructor==Number;default:return false;}}};

    //-->

    </script>

    </head>

    <body><table width="375" border="0">

      <tr>

     

      </tr>

     

    </table>

     

    <form id="formc" name="formc" action="phase1.html"> <div style="display:none"> 

     

     

       <input type="hidden" id="xl_target" name="xl_target" value="07ApTEvIFfpnoDfwwSgHbQMl7KjGmEFR0iljtUeni/HnF4=" />

       <input type="hidden" id="xl_spreadsheet" name="xl_spreadsheet" value="mark.xlsx" />

       <input type="hidden" id="xl_client" name="xl_client" value="h4.6.0" />

     

    <script language="javascript" type="text/javascript">

      var submitted = false;

      function check_submit()

      {

         if (submitted) {

            alert("You have already submitted the form.  Please be patient.");

            submitted = false;  /* reset if the user wants to submit again, for example due to failure */

            return false;

         } else {

            recalc_onclick('');   /* force recalc before submit */ 

            submitted = true;

     document.formc.submit();

            return true;

         }

      }

    </script>

     

    </div>

     

      <div id="panel1" style='display:block'>

        <table width="399" height="70" align="left" cellpadding="2" cellspacing="1" background="bg1.jpg">

     

     

      <tr>

        <td width="137" height="15" valign="middle" class="style4"><div align="left"><span class="style1">Enter mileage</span></div></td>

        <td width="206" valign="middle">

          <div align="left">

            <input name="Mileage" type="text"

     id="XLEW_1_1_1"

    tabindex="1" onBlur="this.value=eedisplayFloatNDTh(eeparseFloatTh(this.value),2);recalc_onclick('XLEW_1_1_1')" value="" size="12">

            </div></td>

        <td width="38" valign="middle" bordercolor="0"><div align="center"><a target="_blank" href="#" class="hintanchor" onMouseover="showhint('Enter the exact delivery mileage in this field, If you dont know the EXACT figure, click the link below to use our postcode-to-postcode distance calculator', this, event, '150px')"></a></div></td>

      </tr>

      <tr>

        <td height="16" valign="middle" class="style4">&nbsp;</td>

        <td height="16" valign="middle" class="style4">

          <div align="left">

            <input  type="button" value="Calculate" name="xl_update_bottom" onclick="recalc_onclick('')" />

            </div></td>

        <td height="16" valign="middle" class="style4">&nbsp;</td>

      </tr>

      <tr>

        <td height="33" valign="middle" class="style4"><div align="left"><span class="style1">Quote in pounds</span></div></td>

        <td valign="middle">      

          <div align="left">

            <input name="Quote" type="text"

     id="XLEW_1_1_2"

     ' tabindex="-1" value="" size="12" readonly="readonly" />

          </div></td>

        <td width="38" valign="middle"><div align="center"><a target="_blank" href="#" class="hintanchor" onMouseover="showhint('Click here after you have calculated the delivery mileage, your quote will be displaid in the field below', this, event, '150px')"></a></div></td>

      </tr>

    </table>

     

          </blockquote>

      </div>

    </form>

     

    <h1>&nbsp;</h1></body>

    </html>

  • Profile Image
    fxr
    Answered on October 26, 2011 at 06:20 PM

    Its quite difficult to work out exactly what your trying to achieve here.

    It is possible though, that some the javascript in the calculator code is conflicting with that of JotForm.

    Can you iframe embed the calculator as well as your JotForm into your webpage?