Add 5 textbox inputs into total.textbox

Topics: ASP.NET 2.0
Mar 8, 2012 at 1:57 AM

I have 5 texboxes in a form that I want to auto total into the Total.textbox, can someone get me started. Thanks

The textboxes are as follows:

Primary_A_dues

B_dues

C_dues

D_dues

Donation

Total

 

Mar 8, 2012 at 5:47 PM
Edited Mar 8, 2012 at 5:51 PM

This is the code I am using which is returning this error: 

SCRIPT5007: Unable to get value of the property 'value': object is null or undefined
membership_app.aspx, line 114 character 10

 

 <script type="text/javascript">

     function DoSum() {
         document.getElementById("Sum").value =
    parseInt(document.getElementById("Primary_A_dues").value) +
    parseInt(document.getElementById("B_dues").value) +
    parseInt(document.getElementById("C_dues").value) +
    parseInt(document.getElementById("D_dues").value) +
    parseInt(document.getElementById("Donation").value)
     }

</script>

Mar 8, 2012 at 6:05 PM

Hi Jerry, what does the HTML look like for this?

Mar 8, 2012 at 6:11 PM

Here is the part with the textboxes I am trying to sum up, is there a better way or better code that would auto sum without the button?  Now the page doesn't come up at all with the above javascript.  Do you need the entire form?

            <td style="width: 71px">
                <asp:TextBox ID="Primary_A_dues" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="Primary_A_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="Primary_A_dues" 
                    WatermarkText="Enter $40, $25 or $10.00">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px">
                <br />
                <br />
            </td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                Additional B</td>
            <td style="width: 124px">
                <asp:TextBox ID="B_last_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px">
                <asp:TextBox ID="B_first_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px" width="30px">
                <asp:TextBox ID="B_under_18" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td style="width: 50px">
                <asp:TextBox ID="B_number" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 71px">
                <asp:TextBox ID="B_dues" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="B_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="B_dues" WatermarkText="Enter $15.00 for B">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px; height: 44px;">
                Additional C</td>
            <td style="width: 124px; height: 44px;">
                <asp:TextBox ID="C_last_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 44px;">
                <asp:TextBox ID="C_first_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px; height: 44px;" width="30px">
                <asp:TextBox ID="C_under_18" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td style="width: 50px; height: 44px;">
                <asp:TextBox ID="C_number" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="height: 44px; width: 71px">
                <asp:TextBox ID="C_dues"  runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="C_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="C_dues" WatermarkText="Enter $15.00 for C">
                </ajaxToolkit:TextBoxWatermarkExtender>
                </td>
            <td style="width: 90px; height: 44px;">
                &nbsp;</td>
            <td style="width: 559px; height: 44px;">
                </td>
        </tr>
        <tr>
            <td style="width: 203px; height: 43px;">
                Additional D</td>
            <td style="width: 124px; height: 43px;">
                <asp:TextBox ID="D_last_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 43px;">
                <asp:TextBox ID="D_first_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px; height: 43px;" width="30px">
                <asp:TextBox ID="D_under_18" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td style="width: 50px; height: 43px;">
                <asp:TextBox ID="D_number" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 71px; height: 43px">
                <asp:TextBox ID="D_dues"  runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="D_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="D_dues" WatermarkText="Enter $15.00 for D">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px; height: 43px;">
                </td>
            <td style="width: 559px; height: 43px;">
                </td>
        </tr>
        <tr>
            <td style="width: 203px; height: 23px;">
                Temporary B</td>
            <td style="width: 124px; height: 23px;">
                <asp:TextBox ID="Temporary_B_last_name" runat="server"></asp:TextBox>
                </td>
            <td style="width: 104px; height: 23px;">
                <asp:TextBox ID="Temporary_B_first_name" runat="server"></asp:TextBox>
                </td>
            <td style="width: 58px; height: 23px;" width="30px">
                </td>
            <td style="width: 50px; height: 23px;">
                Donation</td>
            <td style="height: 23px; width: 71px">
                <asp:TextBox ID="Donation" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="Donation_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="Donation" WatermarkText="Enter $ amount">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px; height: 23px;">
                &nbsp;</td>
            <td style="width: 559px; height: 23px;">
             </td>
            </tr>
                
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                Total Dues</td>
            <td style="width: 71px">
                <asp:TextBox ID="Total" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="Total_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="Total" WatermarkText="Enter total $ of above ">
                </ajaxToolkit:TextBoxWatermarkExtender>
                <input type="text" id="Sum" style="width:30px"/> 
<input type="button" value="Sum" onclick="DoSum()"/>
            </td>
Mar 8, 2012 at 6:50 PM

Here is the entire form, I am starting from scratch.

<%@ Page Title="" Language="C#" MasterPageFile="~/themes/Portraitpress1/site.master" AutoEventWireup="true" CodeFile="membership_app.aspx.cs" Inherits="membership_app" %>

<%@ Import Namespace="BlogEngine.Core" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Text" %>

<%@ Register
    Assembly="AjaxControlToolkit"
    Namespace="AjaxControlToolkit"
    TagPrefix="ajaxToolkit" %>

    <script runat="server">  

    private string CreateRow(string label, string value)
    {
        return string.Format(
            "<tr><td><b>{0}</b></td><td>{1}</td></tr>",
            HttpUtility.HtmlEncode(label),
            HttpUtility.HtmlEncode(value));
    }    

    protected void Button2_Click(object sender, EventArgs e)
    {
        using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress(BlogSettings.Instance.Email);

            mail.To.Add("treasurer@sahcinfo.org");
            mail.To.Add("membership@sahcinfo.org");
            mail.To.Add("beditor@sahcinfo.org");
            mail.To.Add("president@sahcinfo.org");
            mail.To.Add("webmaster@sahcinfo.org");

            

            mail.Subject = "Online SAHC Membership Application";

            StringBuilder sb = new StringBuilder();
            sb.Append("<table border=\"1\" cellpadding=\"3\">");

            sb.Append(CreateRow("Primary A Name",
            string.Format("{0} {1}", Primary_first_name.Text, Primary_last_name.Text)));           
            sb.Append(CreateRow("Primary A Under 18", Primary_under_18.Text));
            sb.Append(CreateRow("Primary A Number", Primary_A_number.Text));
            sb.Append(CreateRow("Bulletin Format", Bulletin_Format.Text));
            sb.Append(CreateRow("Additional B Name",
            string.Format("{0} {1}", B_first_name.Text, B_last_name.Text)));
            sb.Append(CreateRow("Additional B Under 18", B_under_18.Text));
            sb.Append(CreateRow("Additional B Number", B_number.Text));
            sb.Append(CreateRow("Additional C Name",
            string.Format("{0} {1}", C_first_name.Text, C_last_name.Text)));
            sb.Append(CreateRow("Additional C Under 18", C_under_18.Text));
            sb.Append(CreateRow("Additional C Number", C_number.Text));            
            sb.Append(CreateRow("Additional D Name",
            string.Format("{0} {1}", D_first_name.Text, D_last_name.Text)));
            sb.Append(CreateRow("Additional D Under 18", D_under_18.Text));
            sb.Append(CreateRow("Additional D Number", D_number.Text));

            sb.Append(CreateRow("Temporary B Name",
            string.Format("{0} {1}", Temporary_B_first_name.Text,Temporary_B_last_name.Text)));
            
            
            sb.Append(CreateRow("Donation", Donation.Text));
            sb.Append(CreateRow("Total Dues", Total.Text));
            sb.Append(CreateRow("Address/Apartment", 
            string.Format("{0} {1}", Address.Text,Apt.Text)));
            sb.Append(CreateRow("City/State/Zip",
            string.Format("{0}, {1} {2}", City.Text, State.Text, Zip.Text)));
            sb.Append(CreateRow("Phone/Email",
            string.Format("{0} {1}", Phone.Text, Email.Text)));
            sb.Append(CreateRow("Visiting Dates", Visiting_dates.Text)); 
            sb.Append(CreateRow("Address Listed/Phone Listed/Email Listed",
            string.Format("{0}, {1} {2}", Address_listed.Text, Phone_listed.Text, Email_listed.Text)));            
            sb.Append(CreateRow("Referred by", Referred_by.Text));
            sb.Append(CreateRow("Explain other", Explain_other.Text));
            sb.Append(CreateRow("Assumption/Date",
            string.Format("{0} {1}", Assumption.Text, Date.Text)));    
            sb.Append(CreateRow("Payment made by", Payment_made_by.Text));                      
                     
                       
            sb.Append("</table>");

            mail.IsBodyHtml = true;
            mail.Body = sb.ToString();

            string errorMessage = Utils.SendMailMessage(mail);
            if (string.IsNullOrEmpty(errorMessage))
            {
                // success
                Response.Redirect("http://sahcinfo.org/membership_complete.htm");
            }
            else
            {
                Response.Write("An error occurred sending the email.  Error: " + errorMessage);
            }
        }
        
    }
</script>


 







<asp:Content ID="Content1" ContentPlaceHolderID="cphBody" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>



   

<h3>SAHC Membership Application</h3>
    <p>
        Important This membership application is for online payment only, if you are 
        mailing in your payment please do not use this application unless you print it 
        out and mail it with your payment.</p>
    <p>
&nbsp;This form will not submit unless all required fields indicated by the red asterisk 
        are filled in. If the form does not submit, the fields indicated by the red text 
        are missing data. After submitting you will be directed to the secure payment 
        page.</p>
    <p>
&nbsp;SAHC dues for the year Oct. 1, 2011 to Sep. 30, 2012</p>
    <p>
&nbsp;$40.00 for a Primary (A) member who elects to receive the printed version of 
        $25.00 for a Primary (A) member who elects to receive the electronic PDF version 
        of The Bulletin. Members who choose this option are responsible for downloading 
        the electronic issue from the club website each month.</p>
    <p>
&nbsp;$15.00 for non-Primary (B, C, D, etc) members.</p>
    <p>
&nbsp;$10.00 for one Primary (A) and one non-Primary (B) Guest Membership. * Fill out 
        the Primary (A) and Additional (B) name fields, the Email field, and the 
        Visiting Dates field. Also complete the Assumption of Risk �YES� field and 
        associated date field before submitting the form. No other fields required.</p>
    <p>
&nbsp;Any �A� member who wishes to switch from a PDF Bulletin to a printed Bulletin may 
        do so at any time by paying the extra $15.00.</p>
&nbsp;<table style="width: 768px">
        <tr>
            <td style="width: 203px">
                Member</td>
            <td style="width: 124px">
                Last Name</td>
            <td style="width: 104px">
                First Name</td>
            <td style="width: 58px" width="30px">
                yes/no Under 18</td>
            <td style="width: 50px">
                Include # if former member</td>
            <td width="60px" style="width: 71px">
                Dues</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                <asp:DropDownList ID="Bulletin_Format" runat="server" Width="165px">
                    <asp:ListItem>Choose Bulletin Format</asp:ListItem>
                    <asp:ListItem>$40.00 Printed Bulletin</asp:ListItem>
                    <asp:ListItem>$25.00 eBulletin</asp:ListItem>
                    <asp:ListItem>$10.00 Temporary Membership</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                Primary A</td>
            <td style="width: 124px">
                <asp:TextBox ID="Primary_last_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px">
                <asp:TextBox ID="Primary_first_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px" width="30px">
                <asp:TextBox ID="Primary_under_18" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td style="width: 50px">
                <asp:TextBox ID="Primary_A_number" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 71px">
                <asp:TextBox ID="Primary_A_dues" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="Primary_A_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="Primary_A_dues" 
                    WatermarkText="Enter $40, $25 or $10.00">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px">
                <br />
                <br />
            </td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                Additional B</td>
            <td style="width: 124px">
                <asp:TextBox ID="B_last_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px">
                <asp:TextBox ID="B_first_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px" width="30px">
                <asp:TextBox ID="B_under_18" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td style="width: 50px">
                <asp:TextBox ID="B_number" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 71px">
                <asp:TextBox ID="B_dues" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="B_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="B_dues" WatermarkText="Enter $15.00 for B">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px; height: 44px;">
                Additional C</td>
            <td style="width: 124px; height: 44px;">
                <asp:TextBox ID="C_last_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 44px;">
                <asp:TextBox ID="C_first_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px; height: 44px;" width="30px">
                <asp:TextBox ID="C_under_18" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td style="width: 50px; height: 44px;">
                <asp:TextBox ID="C_number" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="height: 44px; width: 71px">
                <asp:TextBox ID="C_dues"  runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="C_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="C_dues" WatermarkText="Enter $15.00 for C">
                </ajaxToolkit:TextBoxWatermarkExtender>
                </td>
            <td style="width: 90px; height: 44px;">
                &nbsp;</td>
            <td style="width: 559px; height: 44px;">
                </td>
        </tr>
        <tr>
            <td style="width: 203px; height: 43px;">
                Additional D</td>
            <td style="width: 124px; height: 43px;">
                <asp:TextBox ID="D_last_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 43px;">
                <asp:TextBox ID="D_first_name" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px; height: 43px;" width="30px">
                <asp:TextBox ID="D_under_18" runat="server" Width="30px"></asp:TextBox>
            </td>
            <td style="width: 50px; height: 43px;">
                <asp:TextBox ID="D_number" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 71px; height: 43px">
                <asp:TextBox ID="D_dues"  runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="D_dues_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="D_dues" WatermarkText="Enter $15.00 for D">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px; height: 43px;">
                </td>
            <td style="width: 559px; height: 43px;">
                </td>
        </tr>
        <tr>
            <td style="width: 203px; height: 23px;">
                Temporary B</td>
            <td style="width: 124px; height: 23px;">
                <asp:TextBox ID="Temporary_B_last_name" runat="server"></asp:TextBox>
                </td>
            <td style="width: 104px; height: 23px;">
                <asp:TextBox ID="Temporary_B_first_name" runat="server"></asp:TextBox>
                </td>
            <td style="width: 58px; height: 23px;" width="30px">
                </td>
            <td style="width: 50px; height: 23px;">
                Donation</td>
            <td style="height: 23px; width: 71px">
                <asp:TextBox ID="Donation" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="Donation_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="Donation" WatermarkText="Enter $ amount">
                </ajaxToolkit:TextBoxWatermarkExtender>
            </td>
            <td style="width: 90px; height: 23px;">
                &nbsp;</td>
            <td style="width: 559px; height: 23px;">
             </td>
            </tr>
                
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                Total Dues</td>
            <td style="width: 71px">
                <asp:TextBox ID="Total" runat="server"></asp:TextBox>
                <ajaxToolkit:TextBoxWatermarkExtender ID="Total_TextBoxWatermarkExtender" 
                    runat="server" TargetControlID="Total" WatermarkText="Enter total $ of above ">
                </ajaxToolkit:TextBoxWatermarkExtender>
               
            </td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px; height: 23px;">
                Address</td>
            <td style="width: 124px; height: 23px;">
                <asp:TextBox ID="Address" runat="server" Width="225px"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 23px;">
                Apartment #</td>
            <td style="width: 58px; height: 23px;" width="30px">
                <asp:TextBox ID="Apt" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 50px; height: 23px;">
                </td>
            <td style="width: 71px; height: 23px">
                </td>
            <td style="width: 90px; height: 23px;">
                </td>
            <td style="width: 559px; height: 23px;">
                </td>
        </tr>
        <tr>
            <td style="width: 203px">
                City</td>
            <td style="width: 124px">
                <asp:TextBox ID="City" runat="server" Width="225px"></asp:TextBox>
            </td>
            <td style="width: 104px">
                State</td>
            <td width="60px">
                <asp:TextBox ID="State" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                Phone</td>
            <td style="width: 124px">
                <asp:TextBox ID="Phone" runat="server" Width="225px"></asp:TextBox>
            </td>
            <td style="width: 104px">
                ZIP</td>
            <td style="width: 58px" width="30px">
                <asp:TextBox ID="Zip" runat="server" Width="60px"></asp:TextBox>
            </td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px; height: 23px;">
                Email</td>
            <td style="width: 124px; height: 23px;">
                <asp:TextBox ID="Email" runat="server" Width="225px"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 23px;">
                </td>
            <td style="width: 58px; height: 23px;" width="30px">
                </td>
            <td style="width: 50px; height: 23px;">
                </td>
            <td style="width: 71px; height: 23px">
                </td>
            <td style="width: 90px; height: 23px;">
                </td>
            <td style="width: 559px; height: 23px;">
                </td>
        </tr>
        <tr>
            <td colspan="3">
                List my address in the membership directory</td>
            <td style="width: 58px" width="30px">
                <asp:CheckBox ID="Address_listed" runat="server" />
            </td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td colspan="3">
                List my phone number in the membership directory</td>
            <td style="width: 58px" width="30px">
                <asp:CheckBox ID="Phone_listed" runat="server" />
            </td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="height: 23px;" colspan="3">
                List my email address in the membership directory</td>
            <td style="width: 58px; height: 23px;" width="30px">
                <asp:CheckBox ID="Email_listed" runat="server" />
            </td>
            <td style="width: 50px; height: 23px;">
                </td>
            <td style="width: 71px; height: 23px">
                </td>
            <td style="width: 90px; height: 23px;">
                </td>
            <td style="width: 559px; height: 23px;">
                </td>
        </tr>
        <tr>
            <td colspan="2">
                How did you hear about SAHC</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px; height: 23px;">
                <asp:DropDownList ID="Referred_by" runat="server">
                    <asp:ListItem>Choose one</asp:ListItem>
                    <asp:ListItem Value="Web Search">Web search</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td style="width: 124px; height: 23px;">
                <asp:TextBox ID="Explain_other" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 23px;">
                </td>
            <td style="width: 58px; height: 23px;" width="30px">
                </td>
            <td style="width: 50px; height: 23px;">
                </td>
            <td style="width: 71px; height: 23px">
                </td>
            <td style="width: 90px; height: 23px;">
                </td>
            <td style="width: 559px; height: 23px;">
                </td>
        </tr>
        <tr>
            <td style="height: 15px;" colspan="2">
                By submitting this form you are agreeing to accept the Assunption of Risk below</td>
            <td style="width: 104px; height: 15px;">
                <asp:TextBox ID="Assumption" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px; height: 15px;" width="30px">
                </td>
            <td style="width: 50px; height: 15px;">
                </td>
            <td style="width: 71px; height: 15px">
                </td>
            <td style="width: 90px; height: 15px;">
                </td>
            <td style="width: 559px; height: 15px;">
                </td>
        </tr>
        <tr>
            <td style="width: 203px; height: 23px;">
                Date</td>
            <td style="width: 124px; height: 23px; text-align: justify;">
                &nbsp;<asp:TextBox ID="Date" runat="server"></asp:TextBox>
            </td>
            <td style="width: 104px; height: 23px;">
                </td>
            <td style="width: 58px; height: 23px;" width="30px">
                </td>
            <td style="width: 50px; height: 23px;">
                </td>
            <td style="width: 71px; height: 23px">
                </td>
            <td style="width: 90px; height: 23px;">
                </td>
            <td style="width: 559px; height: 23px;">
                </td>
        </tr>
        <tr>
            <td colspan="2">
                Enter name of person paying if different then the Primary member</td>
            <td style="width: 104px">
                <asp:TextBox ID="Payment_made_by" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td colspan="2">
                Visiting dates for tempory membership</td>
            <td style="width: 104px">
                <asp:TextBox ID="Visiting_dates" runat="server"></asp:TextBox>
            </td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                                    <asp:Button ID="Button2" runat="server" Text="Submit" OnClick="Button2_Click" Width="101px"/></td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 203px">
                &nbsp;</td>
            <td style="width: 124px">
                &nbsp;</td>
            <td style="width: 104px">
                &nbsp;</td>
            <td style="width: 58px" width="30px">
                &nbsp;</td>
            <td style="width: 50px">
                &nbsp;</td>
            <td style="width: 71px">
                &nbsp;</td>
            <td style="width: 90px">
                &nbsp;</td>
            <td style="width: 559px">
                &nbsp;</td>
        </tr>
         <tr>
                                <td colspan="2" style="height: 33px">
                                     
                                  
                                </td>
                                <td style="width: 100px; height: 33px;" valign="bottom" align="right">
                                    &nbsp;</td>
                            </tr>
    </table>

     <h3>
                    Member Application and Acknowledgment of Responsibility, Express Assumption of Risk, and Release of Liability
                </h3>
                <ul>
                    <li>I understand that during my membership in the Southern Arizona Hiking Club and during participation in any club Activity, I may be exposed to a variety of hazards and risks, foreseen or unforeseen, which are inherent in each Activity and cannot be eliminated without destroying the unique character of the Activity. These inherent risks include, but are not limited to, the dangers of serious personal injury, property damage, and death (�Injuries and Damages�) from exposure to the hazards of travel, and the Southern Arizona Hiking Club has not tried to contradict or minimize my understanding of these risks. I know that Injuries and Damages can occur by natural causes or activities of other persons, animals, club members, guides and assistants or third parties, either as a result of negligence or because of other reasons. I understand that risks of such Injuries and Damages are involved in adventure travel such as Southern Arizona Hiking Club Activities and I appreciate that I may have to exercise extra care for my own person and for others around me in the face of such hazards. I further understand that there may not be rescue or medical persons, facilities, or expertise necessary to deal with the Injuries and Damages to which I may be exposed on any Activity.
                
                        <br />
                        <br />
                        In consideration for my acceptance as a member in the Club and as a participant in any Club Activity, I confirm my understanding that:

                        <br />
                    </li>
                    <li>I have read any rules and conditions applicable to the Activities made available 
                        to me; I will pay any costs and fees for the Activities; and I acknowledge my 
                        participation is at my own discretion and the discretion of the Guide(s).
                    </li>
                    <li>The Activities officially begin and end at the location(s) designated by the 
                        Southern Arizona Hiking Club. The Activities may include carpooling, 
                        transportation, or private transit to and from the Activity, and I am personally 
                        responsible for all risks associated with this travel.</li>
                    <li>This Agreement is intended to be as broad and inclusive as is permitted by law. 
                        If any provision or any part of any provision of this Agreement is held to be 
                        invalid or legally unenforceable for any reason, the remainder of this Agreement 
                        shall not be affected thereby and shall remain valid and fully enforceable.</li>
                    <li>To the fullest extent allowed by law, I agree to WAIVE, DISCHARGE CLAIMS, AND 
                        RELEASE FROM LIABILITY the Southern Arizona Hiking Club, its officers, 
                        directors, employees, agents, and leaders from any and all liability on account 
                        of, or in any way resulting from Injuries and Damages, even if caused by 
                        negligence of the Southern Arizona Hiking Club, its officers, directors, 
                        employees, agents, and leaders, in any way connected with this Activity. I 
                        further agree to HOLD HARMLESS the Southern Arizona Hiking Club, its officers, 
                        directors, employees, agents, and leaders from any claims, damages, injuries or 
                        losses caused by my own negligence while a member of the club or a participant 
                        in any Activity. I understand and intend that this assumption of risk and 
                        release is binding upon my heirs, executors, administrators and assigns, and 
                        includes any minors accompanying me.</li>
                    <li>I have read this document in its entirety and I freely and voluntarily assume 
                        all risks of such Injuries and Damages and notwithstanding such risks, I agree 
                        to membership in the Southern Arizona Hiking Club and may participate in any 
                        Club Activity.</li>
    </ul>
    <p>
        Please allow up to five days for receipt of your membership number. You may 
        participate in any hike prior to receiving your number. When signing in for a 
        hike, please inform the guide that you are a new member and write &quot;new member&quot; 
        in the member number field.&quot;
    </p>
    <p>
        Mailing Address - SAHC - PO Box 32257 - Tucson, AZ 85715
    </p>
    <p>
        &nbsp;</p>


</asp:Content>

Mar 8, 2012 at 7:49 PM

Hi Jerry, at first glance I'm thinking there might be a problem with the ID's.

The "runat server" will affect their values, can you inspect their values in the browser to verify this?

perhaps something like 

document.getElementById('<%=Primary_A_dues.ClientID %>').value

 

I'm not familiar with the ajaxToolkit, looks like that's entering suggestive text and whether or not you could use that to extract values as well.

The onfocus and onblur events could be used as an alternative to using the sum button.

So for each of the inputs that you want summed, attach the events onFocus="startSum" onBlur="stopSum"

It might look something like this inside your script tags:

 

$(document).ready(function () {
	
        var dueA = document.getElementById('<%=Primary_A_dues.ClientID %>');
	var dueB = document.getElementById('<%=B_dues.ClientID %>');
  	var dueC = document.getElementById('<%=C_dues.ClientID %>');
  	var dueD = document.getElementById('<%=D_dues.ClientID %>');
	dueA.onfocus = startSum;
	dueA.onblur = stopSum;
	dueB.onfocus = startSum;
	dueB.onblur = stopSum;
	dueC.onfocus = startSum;
	dueC.onblur = stopSum;
	dueD.onfocus = startSum;
	dueD.onblur = stopSum;
  				
     }); 

 

function startSum(){
  sumInterval = setInterval(sum,1);
}
function sum(){	
	document.getElementById('<%=Sum.ClientID %>').value =
  	parseInt(document.getElementById('<%=Primary_A_dues.ClientID %>').value) +
	parseInt(document.getElementById('<%=B_dues.ClientID %>').value) +
  	parseInt(document.getElementById('<%=C_dues.ClientID %>').value) +
  	parseInt(document.getElementById('<%=D_dues.ClientID %>').value) +
  	parseInt(document.getElementById('<%=Donation.ClientID %>').value);  
}

function stopSum(){
  clearInterval(sumInterval);
}

It's fairly crude and untested, but if it works you could tidy it up, maybe attach the events with jQuery and what naught.

 

Mar 8, 2012 at 8:08 PM
Edited Mar 8, 2012 at 8:26 PM

Thanks, I gave it a try and get the same error:

 

SCRIPT5007: The value of the property '$' is null or undefined, not a Function object
membership_app.aspx, line 119 character 5

 

I added this

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

 

and now get this error.

 

Also get this in the sum textbox     NaN

 

The value of the property 'Calculate' is null or undefined, not a Function object 


Mar 8, 2012 at 8:28 PM

Looks like jQuery is absent, try it using window.onload, not ideal, but just to test).

Swap $(document).ready for this

window.onload = function () {
	
        var dueA = document.getElementById('<%=Primary_A_dues.ClientID %>');
	var dueB = document.getElementById('<%=B_dues.ClientID %>');
  	var dueC = document.getElementById('<%=C_dues.ClientID %>');
  	var dueD = document.getElementById('<%=D_dues.ClientID %>');
	dueA.onfocus = startSum;
	dueA.onblur = stopSum;
	dueB.onfocus = startSum;
	dueB.onblur = stopSum;
	dueC.onfocus = startSum;
	dueC.onblur = stopSum;
	dueD.onfocus = startSum;
	dueD.onblur = stopSum;
	alert("so far so good");
  				
     }); 

Meanwhile, I'll copy the code for the complete form and play around with it.

Mar 8, 2012 at 8:43 PM

No errors but no sum either.

Mar 8, 2012 at 9:00 PM

Did the alert pop up?

I'm copying form code now and will set up a test page.

Mar 8, 2012 at 10:11 PM
Edited Mar 8, 2012 at 10:53 PM

Sorted, this works.

I'll leave it to your good self to make elegant.

 

<script type="text/javascript">
//<![CDATA[
    window.onload = function () {
        var dueA = document.getElementById('<%=Primary_A_dues.ClientID %>');
        var dueB = document.getElementById('<%=B_dues.ClientID %>');
        var dueC = document.getElementById('<%=C_dues.ClientID %>');
        var dueD = document.getElementById('<%=D_dues.ClientID %>');
        dueA.onfocus = startSum;
        dueA.onblur = stopSum;
        dueB.onfocus = startSum;
        dueB.onblur = stopSum;
        dueC.onfocus = startSum;
        dueC.onblur = stopSum;
        dueD.onfocus = startSum;
        dueD.onblur = stopSum;        
    }

    function startSum() {
        sumInterval = setInterval(sum, 1);
    }
    function sum() {
    document.getElementById('<%=Total.ClientID %>').value =
  	document.getElementById('<%=Primary_A_dues.ClientID %>').value * 1 +
	document.getElementById('<%=B_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=C_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=D_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=Donation.ClientID %>').value * 1;
    }

    function stopSum() {
        clearInterval(sumInterval);
    }
    
//]]>
</script>

Edit:

I just noticed I left out the events for the donation field

 

<script type="text/javascript">
//<![CDATA[
    window.onload = function () {
        var dueA = document.getElementById('<%=Primary_A_dues.ClientID %>');
        var dueB = document.getElementById('<%=B_dues.ClientID %>');
        var dueC = document.getElementById('<%=C_dues.ClientID %>');
        var dueD = document.getElementById('<%=D_dues.ClientID %>');
        var don = document.getElementById('<%=Donation.ClientID %>');
        dueA.onfocus = startSum;
        dueA.onblur = stopSum;
        dueB.onfocus = startSum;
        dueB.onblur = stopSum;
        dueC.onfocus = startSum;
        dueC.onblur = stopSum;
        dueD.onfocus = startSum;
        dueD.onblur = stopSum;
        don.onfocus = startSum;
        don.onblur = stopSum;          
    }

    function startSum() {
        sumInterval = setInterval(sum, 1);
    }
    function sum() {
    document.getElementById('<%=Total.ClientID %>').value =
  	document.getElementById('<%=Primary_A_dues.ClientID %>').value * 1 +
	document.getElementById('<%=B_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=C_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=D_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=Donation.ClientID %>').value * 1;
    }

    function stopSum() {
        clearInterval(sumInterval);
    }
    
//]]>
</script>

I removed the ajax stuff in the test page, so hopefully the window.onload doesn't interfere with the ajax.

You could probably get away with using window.onload if there are no other load events, it will save on loading up jQuery. As I was saying, I'm not familiar with the ajax tool kit, but I would be surprised if it can't be done with that.

Mar 8, 2012 at 11:26 PM

It works great, thank you very much for your generous help.

Mar 8, 2012 at 11:46 PM

Good stuff, just remember it's fairly basic.

It will handle any numbers, so 50.50 is good or 50 or white space, but if anything else is entered, say $50 then you get NAN.

Which isn't a disaster, but you might want to do something with that.

Cheers for now.

Apr 18, 2012 at 2:06 AM

Andy, if I had a text box named member.txt and it was filled in is there a way to auto apply a discount (negative number)  to say a textbox named Total_amt using the above code? 

Or if that is too complicated how about a texbox named Discount.txt that would apply a negative number like -10 to the total?

 

Thanks for your generous help.

Apr 18, 2012 at 9:23 AM
Edited Apr 18, 2012 at 9:25 AM

Shouldn't be too difficult, I'm on the hop just now, but can look at it later today.

You would probably be best to use a discount field anyway so that you don't have to hard code that value.

So say the member discount is 10%, then in the auto sum function you would validate the member.txt and if it's good, multiply the total by (100 - 10)/100

Roughly:

 

var memberDiscount = document.getElementById('<%=discountField%>').value * 1;
memberDiscount = (100 - memberDiscount)/100;

var validMember = validateMember();

function sum() {
    var runningTotal =
  	document.getElementById('<%=Primary_A_dues.ClientID %>').value * 1 +
	document.getElementById('<%=B_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=C_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=D_dues.ClientID %>').value * 1 +
  	document.getElementById('<%=Donation.ClientID %>').value * 1;
    	if(validMember) {
        	runningTotal *= memberDiscount;
    	}
    	document.getElementById('<%=Total.ClientID %>').value = runningTotal;
    }

 

validateMember() would return true or false depending on how you want to validate the member field.

Apr 18, 2012 at 11:40 AM
Edited Apr 18, 2012 at 12:48 PM

Sounds good, actually there are two text fields that if filled in would offer discounts, they are as follows:

work_scholarship.txt if validated would result in a 60.00 discount

member_of.txt if validated would result in a 10.00 discount

So if either were validated the discount values could be put in the discount.text as negative and would be represented in the total_amt_due.txt or be subtracted from 

Amount_enter_195.txt and the total_amt_due would be correct.

I think the discounts being applied to the discount.txt as a negative number and then subtracted from the total_amt_due.txt would be the way to go.

Apr 18, 2012 at 9:55 PM
Edited Apr 18, 2012 at 10:10 PM

Hi Jerry, 

This tidies up previous code, but still uses global variables, which is probably OK here... if there are any conflicts it's easily sorted.

This corresponds to the form on the TFOTM site, so you should be able to copy and paste over the existing script.

<script type="text/javascript">
//<![CDATA[

    var totalsArray;
    var discountsArray;
    var sumInterval;
    var adjuster = 0;
    var scholarDiscount = 60.00;
    var memberDiscount = 10.00;

    window.onload = function () {
        totalsArray = new Array(
            document.getElementById('ctl00_cphBody_Amount_enter_195'),
            document.getElementById('ctl00_cphBody_Child1_amt'),
            document.getElementById('ctl00_cphBody_Child2_amt'),
            document.getElementById('ctl00_cphBody_Child3_amt'),
            document.getElementById('ctl00_cphBody_LadiesT_amt'),
            document.getElementById('ctl00_cphBody_UnisexT_amt')
        );

        for (var i = 0; i < totalsArray.length; i++) {
            totalsArray[i].onfocus = startSum;
            totalsArray[i].onblur = stopSum;
        }

        //You need this in case somebody selects the discount option after filling out the totals
        discountsArray = new Array(
            document.getElementById("ctl00_cphBody_Work_scholarship"),
            document.getElementById("ctl00_cphBody_Member_of")
        );

        for (var j = 0; j < discountsArray.length; j++) {
            discountsArray[j].onfocus = startSum;
            discountsArray[j].onblur = stopSum;
        }

    }

    function startSum() {
        sumInterval = setInterval(sum, 1);
    }
    function sum() {
        var runningTotal = 0;
        for (var j = 0; j < totalsArray.length; j++) {
            runningTotal += (totalsArray[j].value * 1);
        }
        checkForDiscount(runningTotal);
        document.getElementById('ctl00_cphBody_Total_amt_due').value = runningTotal - adjuster;
    }

    function stopSum() {
        clearInterval(sumInterval);
    }

    function checkForDiscount(currentTotal) {
        adjuster = 0;
        document.getElementById("ctl00_cphBody_Discount").value = "0";
        if (currentTotal > 0) {
            if (document.getElementById("ctl00_cphBody_Work_scholarship").value.toLowerCase() == "y") {
                adjuster = scholarDiscount;
                document.getElementById("ctl00_cphBody_Discount").value = "-" + scholarDiscount;
                return; //If you get this discount then you dont get the member discount
            }
            if (document.getElementById("ctl00_cphBody_Member_of").value.toLowerCase() != "none") {
                adjuster = memberDiscount;
                document.getElementById("ctl00_cphBody_Discount").value = "-" + memberDiscount;
            }
        }            
    }    

//]]>

</script>

Apr 18, 2012 at 11:26 PM

Wow I am so impressed with this Andy, thank you so much, it works great!

Do you think you could do one small revision for me?  if I could have the Amount_enter_195.txt either default to 195 or be filled when last_name.txt is validated, this would be great.

Thank you for you for your generous time, your sharing of skills and the time you contribute to BlogEngine.

Apr 18, 2012 at 11:35 PM

No probs, 

I've hit the beer now, so if it's OK I'll do that tomorrow.

Catch you later.

Apr 19, 2012 at 12:22 AM

Hope this is OK, just swap this for the other one.

Probably wouldn't do any harm to add some null checks on the fields, but should be fine... definitely away now.

 

<script type="text/javascript">
//<![CDATA[

    var totalsArray;
    var discountsArray;
    var sumInterval;
    var basePrice = 195;
    var adjuster = 0;
    var scholarDiscount = 60.00;
    var memberDiscount = 10.00;

    window.onload = function () {

        var basePriceField = document.getElementById("ctl00_cphBody_Amount_enter_195");
        basePriceField.value = basePrice;
        basePriceField.readOnly = true;

        totalsArray = new Array(
            basePriceField,
            document.getElementById('ctl00_cphBody_Child1_amt'),
            document.getElementById('ctl00_cphBody_Child2_amt'),
            document.getElementById('ctl00_cphBody_Child3_amt'),
            document.getElementById('ctl00_cphBody_LadiesT_amt'),
            document.getElementById('ctl00_cphBody_UnisexT_amt')
        );

        for (var i = 0; i < totalsArray.length; i++) {
            totalsArray[i].onfocus = startSum;
            totalsArray[i].onblur = stopSum;
        }

        //You need this in case somebody selects the discount option after filling out the totals
        discountsArray = new Array(
            document.getElementById("ctl00_cphBody_Work_scholarship"),
            document.getElementById("ctl00_cphBody_Member_of")
        );

        for (var j = 0; j < discountsArray.length; j++) {
            discountsArray[j].onfocus = startSum;
            discountsArray[j].onblur = stopSum;
        }

    }

    function startSum() {
        sumInterval = setInterval(sum, 1);
    }
    function sum() {
        var runningTotal = 0;
        for (var i = 0; i < totalsArray.length; i++) {
            runningTotal += (totalsArray[i].value * 1);
        }
        checkForDiscount(runningTotal);
        document.getElementById('ctl00_cphBody_Total_amt_due').value = runningTotal - adjuster;
    }

    function stopSum() {
        clearInterval(sumInterval);
    }

    function checkForDiscount(currentTotal) {
        adjuster = 0;
        var discountField = document.getElementById("ctl00_cphBody_Discount");
        discountField.value = "0";
        if (currentTotal > basePrice) {
            if (discountsArray[0].value.toLowerCase() == "y") {
                adjuster = scholarDiscount;
                discountField.value = "-" + scholarDiscount;
                return; //If you get this discount then you dont get the member discount
            }
            if (discountsArray[1].value.toLowerCase() != "none") {
                adjuster = memberDiscount;
                discountField.value = "-" + memberDiscount;
            }
        }            
    }    

//]]>

</script>

 

 

Apr 19, 2012 at 2:00 PM

There is a glitch, I think maybe it was also in the last code, the discounts do not seem to be working and they should be able to get both discounts, the 60 and the 10.

Thanks again for your help.

http://www.tftm.keeponhiking.com/ditd_reg1.aspx

Apr 19, 2012 at 7:22 PM
Edited Apr 19, 2012 at 9:26 PM

Hi Jerry,

I just assumed that if you got the scholar discount then you didn't get the member discount.

There's a comment in the checkForDiscount function to that effect, so it might appear that the discounts aren't working right if you select scholar and then member.

Here's a revised version that should give you both discounts and inserts the default base price.

I gave it a quick once over locally, but if there's any probs let me know.

 

<script type="text/javascript">
//<![CDATA[

    var totalsArray;
    var discountsArray;
    var sumInterval;
    var adjuster = 0;
    var discountField;
    var totalDueField;
    //Change base price or discounts here
    var basePrice = 195.00;    
    var scholarDiscount = 60.00;
    var memberDiscount = 10.00;

    window.onload = function () {
    //Try and keep all field assignment in one place 
        var basePriceField = document.getElementById("ctl00_cphBody_Amount_enter_195");
        basePriceField.value = basePrice;
        basePriceField.readOnly = true;
        discountField = document.getElementById("ctl00_cphBody_Discount");
        totalDueField = document.getElementById('ctl00_cphBody_Total_amt_due');
        discountField.value = "0";
        totalDueField.value = basePrice;

        totalsArray = new Array(
            basePriceField,
            document.getElementById('ctl00_cphBody_Child1_amt'),
            document.getElementById('ctl00_cphBody_Child2_amt'),
            document.getElementById('ctl00_cphBody_Child3_amt'),
            document.getElementById('ctl00_cphBody_LadiesT_amt'),
            document.getElementById('ctl00_cphBody_UnisexT_amt')
        );

        for (var i = 0; i < totalsArray.length; i++) {
            totalsArray[i].onfocus = startSum;
            totalsArray[i].onblur = stopSum;
        }

        //You need this in case somebody selects the discount option after filling out the totals
        discountsArray = new Array(
            document.getElementById("ctl00_cphBody_Work_scholarship"),
            document.getElementById("ctl00_cphBody_Member_of")
        );

        for (var j = 0; j < discountsArray.length; j++) {
            discountsArray[j].onfocus = startSum;
            discountsArray[j].onblur = stopSum;
        }

    }

    function startSum() {
        sumInterval = setInterval(sum, 1);
    }
    function sum() {
        var runningTotal = 0;
        for (var i = 0; i < totalsArray.length; i++) {
            runningTotal += (totalsArray[i].value * 1);
        }
        checkForDiscount();
        totalDueField.value = runningTotal + adjuster;
    }

    function stopSum() {
        clearInterval(sumInterval);
    }

    function checkForDiscount() {
        adjuster = 0;        
        discountField.value = "0";
        
        if (discountsArray[0].value.toLowerCase() == "y") {
            adjuster = adjuster - scholarDiscount;
            discountField.value = adjuster;                
        }
        if (discountsArray[1].value.toLowerCase() != "none") {
            adjuster = adjuster - memberDiscount;
            discountField.value = adjuster;
        }                   
    }    

//]]>
</script>

 

Edited to give default values in discount and total due fields on start up. Also removed current total from checkForDiscounts as this would indeed prevent discounts working on base price only selections.

P.S.

On pottering around with the form:

Use case scenario, what if you have 4 children and want six T-Shirts all in different sizes?

Might not take much in the way of change to accommodate this.

Apr 19, 2012 at 10:54 PM
Edited Apr 19, 2012 at 10:55 PM

Yes this version is working great, good point on the Tshirts, I'll have to ponder it a bit.  Thank you so much again for your generous help Andy, you are definitely very knowledgeable in Javascript,  C#, CSS and probably other areas also.  The BE community is lucky to have you involved.

 

Jerry