Results 1 to 2 of 2

Thread: need help w/js

  1. #1
    Join Date
    May 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help w/js

    Hi, I could use some help with my JS code. I'm sending my completed Captcha form to my email addy. There are several dropdowns, among which are 2 input fields "unitprices" and 2 "quantities". Selecting 1 or both produces a "result" or 2. This works. It should produce "subtotal" and gtotal" but doesn't. First below is the printout of the email sent. Following that is my code. Thanks in advnce.
    =======================================================
    taxrate = 0.00
    unitprice1 = 249.95
    qty1 = 1
    result1 = 249.95
    unitprice2 = 327.95
    qty2 = 2
    result2 = 655.90
    subtotal =
    total =
    Name = chaz
    FromEmailAddress = kirkwebsites@yahoo.com
    x = 37
    y = 8
    =================================================
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    
    </HEAD>
    <BODY bgColor=#FFCC66><center>
       
    <form name="form1" action="http://www.SnapHost.com/captcha/send.aspx" id="ContactUsCaptchaWebForm" method="post">
    <input name="skip_WhereToSend" type="hidden" value="ckdoublenecks@yahoo.com">
    <input name="skip_SnapHostID" type="hidden" value="FYDXPGEUE96F">
    <input name="skip_WhereToReturn" type="hidden" value="http://www.ckdoublenecks.biz/ckorder-thanks.html">
    <input name="skip_Subject" type="hidden" value="My Order Form">
    <input name="skip_ShowUsersIp" type="hidden" value="1">
    <input name="skip_SendCopyToUser" type="hidden" value="1">
    <input type="hidden" name="taxrate" value="0.00"> <!-- 0% sales tax, adjust accordingly -->
    <hr>
    
    <table>
      <tr>
        <th>Product - Unit Price</th>
        <th>Qty</th>
        <th>Item total</th>
      <tr>
    <td align="middle"><select name="unitprice1" onchange="calculate(1)">    
    <OPTION class=highlight value="" selected>Select</OPTION>
    <OPTION class=highlight value="249.95">Violina_conversion -    249.95</OPTION>
    <OPTION class=highlight value="327.95">Pipsqueek_conversion -    327.95</OPTION>
    
    </select></td>
        <td align="middle"><select name="qty1" onchange="calculate(1)">
    <OPTION class=highlight value="" selected>choose</option>
    <OPTION class=highlight value="1">1</option>
    <OPTION class=highlight value="2">2</option>
    
          </select></td>
          <td align="middle">$<input type="text" class="result" name="result1"></td>
        <tr>
        <td align="middle"><select name="unitprice2" onchange="calculate(2)">
    <OPTION class=highlight value="" selected>Select</OPTION>
    <OPTION class=highlight value="249.95">Violina_conversion - 249.95</OPTION>
    <OPTION class=highlight value="327.95">Pipsqueek_conversion - 327.95</OPTION>
    
    </SELECT></td>
        <td align="middle"><select name="qty2" onchange="calculate(2)">
    <OPTION class=highlight value="" selected>choose</option>
    <OPTION class=highlight value="1">1</option>
    <OPTION class=highlight value="2">2</option>
    
    </SELECT></td>
    <td align="middle" align="middle">$<input type="text" class="result" name="result2"></td>
     <tr>
    <td align="middle" colspan=3 class="totals">Subtotal: $<input type="text" name="subtotal"></td>
       <tr><td colspan=3 class="totals">Grand Total: $<input type="text"        name="gtotal"></td>
      <tr>
        <td><i>Name<font color="red">*</font></i>: <input type="text" name="Name" required></td>
        <td><i>E-mail<font color="red">*</font></i>: <input type="email" name="FromEmailAddress" required></td>
      <tr>
        <td><i>Enter web form code<font color="red">*</font></i>:</td>
    <tr>
    <td>
    <IMG src="shakydigit.gif"><font color=red>**</font>
        <input name="skip_CaptchaCode" type="text" maxlength="6" required></td>
    <tr>
        <td colspan="2">
    <a href="http://www.snaphost.com/captcha/ReadyForms/ContactUsForm.aspx">
    <img id="CaptchaImage" alt="Contact Us form" title="HTML code for Contact Us form" src="http://www.SnapHost.com/captcha/CaptchaImage.aspx?id=FYDXPGEUE96F&ImgType=2"></a><p>
    <span onclick="return ReloadCaptchaImage('CaptchaImage');">reload image</span></td>
        <tr>
        <td colspan="3">
    <!-- Please check our ProCaptcha service which is ad-free:
    [url]http://www.SnapHost.com/captcha/ProCaptchaOverview.aspx[/url] -->
    <a href="http://www.snaphost.com/captcha/ProCaptchaOverview.aspx">
    web forms html</a><br>
    
    
    <CENTER><INPUT type=image height=24 alt="submit button" width=129 
    src="rollsubmit.gif">
    
    <center><small>copyright &copy 2000-2016</small><BR>
    Code:
    <script>
        function calculate(n) {
            var p = document.getElementsByName('unitprice'+n)[0].value,
                q = document.getElementsByName('qty'+n)[0].value;
            document.getElementsByName('result'+n)[0].value = (p * q).toFixed(2);
            total();
        }
    
        function total(){
            var s1 = document.querySelectorAll('.result'),
                st = form1.subtotal.value;
            st = 0;
            for (var i = 0; i < s1.length; i++) {
                    var  a = s1[i].value,
                        st = 1*a+1*st;
            }
            form.subtotal.value = st.toFixed(2);
            form.tax.value = (st * form.taxrate.value).toFixed(2);
            form.total.value = (st*1 + form.tax.value*1).toFixed(2);
    
        }
    
        function ReloadCaptchaImage(captchaImageId) {
    	var obj = document.getElementById(captchaImageId);
    	var src = obj.src;
    	var date = new Date();
    	var pos = src.indexOf('&rad=');
    	if (pos >= 0) { src = src.substr(0, pos); }
    	obj.src = src + '&rad=' + date.getTime();
    	return false;
        }
    </script>
    HTML Code:
    </form></CENTER></BODY></HTML>
    Last edited by 12Strings; 03-19-2016 at 01:46 AM. Reason: correction

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This is probably not it, but who knows? This sequence looks useless:

    Code:
                st = form1.subtotal.value;
            st = 0;
    Why bother defining st as the value of a form element if you are going to redefine it as 0 on the very next line? I'm thinking that you might be wanting to carry the original value forward and don't realize that you're throwing it away. But it may be something else, or this and something else.

    Oh, and - do you have two forms? In that same function you have:

    Code:
            form.subtotal.value = st.toFixed(2);
    Is it form1 or form, or do you have both? I think I only see form1 in the markup and see no definition for form as being form1. That's even more likely to be an issue, still not certain though. Maybe both things are, and there could be more. It wouldn't be the first time I've seen multiple inconsistencies in code (my own included, so don't feel bad).

    If after addressing these two issues, you still have a problem, let me know. Please include the updated code.

    One other thing, just because you say 'form', or even 'form1' in your code, it doesn't necessarily mean it's what you think it means. If you know how, temporarily put lines in your code to trap values to the console to see if you're getting at least the raw data you're expecting. If you don't, just make as certain as possible you are referring to the element(s) you think you are.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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