使用 Javascript 将变量传递到购物车

发布于 2024-08-29 21:11:41 字数 13676 浏览 7 评论 0原文

此问题是此问题的扩展:

按日期选择值计算订单价格

我正在尝试根据上一页制作一个会议注册页面,该页面使用 JavaScript 将变量(名称、电子邮件、价格)传递到我组织的过时购物车。我还使用 CSSTricks 的研讨会注册 (http://css-tricks.com/examples/SeminarRegTutorial /

目前,我的继续付款按钮在第 298 行产生“元素未定义”错误(与未解决的上一个问题相同,链接在上面^):

 switch (document.Information.amount.value) {

任何帮助将不胜感激。我对此无计可施。这是页面:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Seminar Registration Form with jQuery</title>

    <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />


    <script src="js/jquery-1.2.6.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/form-fun.jquery.js" type="text/javascript" charset="utf-8"></script>

    <!--[if IE]>
        <style type="text/css">
            legend { 
                position: relative;
                top: -30px;
            }

            fieldset {
                margin: 30px 10px 0 0;
            }
        </style>

        <script type="text/javascript">
            $(function(){
                $("#step_2 legend").css({ opacity: 0.5 });
                $("#step_3 legend").css({ opacity: 0.5 });
            });
        </script>
    <![endif]-->
</head>

<body>


    <div id="page-wrap">

        <h1>MFYC'10 <span>Registration</span></h1>

        <form action="#" name="Information" method="post">

            <fieldset id="step_1">

                <legend>Step 1</legend>

                <label for="num_attendees">
                    How cool are you?
                </label>
                <select id="amount">
                    <option id="0" value="0">Please Choose</option>
                    <option id="prof" value="90.00">Professional</option>
                    <option id="grad" value="55.00">Graduate Student</option>

                </select>

                <br />

                <div id="attendee_1_wrap" class="name_wrap push">
                    <h3>Who are you?</h3>

                    <p>
                    <label for="FirstName">
                            First Name:
                    </label>
                    <input type="text" id="FirstName" class="name_input"></input>
                    </p>

                    <p>
                    <label for="LastName">
                            Last Name:
                    </label>
                    <input type="text" id="LastName" class="name_input"></input>
                    </p>

                    <p>
                    <label for="OfficialTitle">
                            Official Title:
                    </label>
                    <input type="text" id="OfficialTitle" class="name_input"></input>
                    </p>

        <h3>How do we find you?</h3>


                <label for="email">Email: </label>

<input id="email" name="email" class="required email" />
</p>

<p>
<label for="Address">Street Address: </label><input name="Address" id="Address" type="text" size="20" maxlength="75" />
</p>
<p>
<label for="City">City: </label><input name="City" id="City" />
</p>
<p>
<label for="State">State: </label><select name="State" id="State">

<option selected value="IL">IL</option>
    <option value="AL">AL</option>
    <option value="AK">AK</option>
    <option value="AZ">AZ</option>
    <option value="AR">AR</option>
    <option value="CA">CA</option>

    <option value="CO">CO</option>
    <option value="CT">CT</option>
    <option value="DE">DE</option>
    <option value="DC">DC</option>
    <option value="FL">FL</option>
    <option value="GA">GA</option>

    <option value="HI">HI</option>
    <option value="ID">ID</option>
    <option value="IN">IN</option>
    <option value="IA">IA</option>
    <option value="KS">KS</option>
    <option value="KY">KY</option>

    <option value="LA">LA</option>
    <option value="ME">ME</option>
    <option value="MD">MD</option>
    <option value="MA">MA</option>
    <option value="MI">MI</option>
    <option value="MN">MN</option>

    <option value="MS">MS</option>
    <option value="MO">MO</option>
    <option value="MT">MT</option>
    <option value="NE">NE</option>
    <option value="NV">NV</option>
    <option value="NH">NH</option>

    <option value="NJ">NJ</option>
    <option value="NM">NM</option>
    <option value="NY">NY</option>
    <option value="NC">NC</option>
    <option value="ND">ND</option>
    <option value="OH">OH</option>

    <option value="OK">OK</option>
    <option value="OR">OR</option>
    <option value="PA">PA</option>
    <option value="RI">RI</option>
    <option value="SC">SC</option>
    <option value="SD">SD</option>

    <option value="TN">TN</option>
    <option value="TX">TX</option>
    <option value="UT">UT</option>
    <option value="VT">VT</option>
    <option value="VA">VA</option>
    <option value="WA">WA</option>

    <option value="WV">WV</option>
    <option value="WI">WI</option>
    <option value="WY">WY</option>
</select>
</p>
<p>
<label for="Zip">Zip Code: </label><input name="Zip" id="Zip" type="text" value="" size="5" maxlength="10"  />
</p>
<p>
<label for="Phone">Telephone: </label><input name="Phone" id="Phone" type="text" value="" size="10" maxlength="13" />
</p>


                </div>


            </fieldset>

            <fieldset id="step_2">

                <legend>Step 2</legend>

                <p>
                    Do you work in Higher Education?
                </p>


                <input type="radio" id="company_name_toggle_on" name="company_name_toggle_group"></input>
                <label for="company_name_toggle_on">Yes</label>
                &emsp;
                <input type="radio" id="company_name_toggle_off" name="company_name_toggle_group"></input>
                <label for="company_name_toggle_off">No</label>

                <div id="company_name_wrap">
                    <label for="company_name">
                        Which School?
                    </label>
                    <input type="text" id="company_name"></input>
                </div>

                <div class="push">          
                    <p>
                        Will anyone in your group require special accommodations?
                    </p>

                    <input type="radio" id="special_accommodations_toggle_on" name="special_accommodations_toggle"></input>
                    <label for="special_accommodations_toggle_on">Yes</label>
                    &emsp;
                    <input type="radio" id="special_accommodations_toggle_off" name="special_accommodations_toggle"></input>
                    <label for="special_accommodations_toggle_off">No</label>
                </div>
                <div id="special_accommodations_wrap">
                    <label for="special_accomodations_text">
                        Please explain below:
                    </label>
                    <textarea rows="10" cols="10" id="special_accomodations_text"></textarea>
                </div>


            </fieldset>

            <fieldset id="step_3">
                <legend>Step 3</legend>

                <label for="rock">
                    Are you ready to rock?
                </label>
                <input type="checkbox" id="rock"></input>
            <p>
                <INPUT onclick="javascript:PaymentButtonClick()" type=button value="Proceed to payment" name=PaymentButton>

                <img src="images/visa1.gif" />
                <img src="images/mastercard1.gif" />
            </p>

            </fieldset>

        </form>

    </div>

<FORM name="emailForm" action="http://www.its.niu.edu/its/scripts/mailform.asp method=post">

<INPUT type="hidden" value="Conference Registration" name="mf_subject">
<INPUT type="hidden" value="Yes" name="mf_email_results"> 


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="20" name="amount">


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="FirstName">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="22" name="LastName">

<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="64" name="OfficialTitle">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="40" name="email">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="48" name="Address">

<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="City">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="State">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="Zip">


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="Phone">

<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="company_name">


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="20" name="special_accomodations_text">

<INPUT type="hidden" value="[email protected]" name="mf_from">

<INPUT type="hidden" value="[email protected]" name="mf_to">
</FORM>










<FORM name="addform" action="https://webcluster.niu.edu/CreditCard/servlet/Shopping_Cart_Add_Item_Servlet" method="post">

<INPUT type="hidden" value="orient" name="Dept_ID">
<INPUT type="hidden" value="Orientation" name="Product_Name">
<INPUT type="hidden" value="z000000" name="Product_Code">
<INPUT type="hidden" value="7.00" name="amount">
<INPUT type="hidden" value="/orientation/index.shtml" name="return_link">
<INPUT type="hidden" value="http://www.niu.edu" name="return_server">
<INPUT type="hidden" value="1" name="quantity"> <INPUT type="hidden" value="0" name="tax">
<INPUT type="hidden" value="0" name="ship"> <INPUT type="hidden" value="DQ83225" name="sale_id">
<INPUT type="hidden" value="401200" name="sale_acct">
</FORM>


<SCRIPT language="Javascript"> 

function PaymentButtonClick() {



    document.addform.Product_Name.value = document.Information.FirstName.value + ","+ 
                                          document.Information.LastName.value+","+
                                          document.Information.OfficialTitle.value+","+
                                          document.Information.email.name+","+","+
                                          document.Information.Address.value+ "," + 
                                          document.Information.City.value+ "," + 
                                          document.Information.State.value+ "," + 
                                          document.Information.Zip.value+ "," + 
                                          document.Information.Phone.value+ "," + 
                                          document.Information.company_name.value+ "," + 
                                          document.Information.special_accomodations_text.value;

    document.addform.Product_Code.value = document.Information.LastName.value;


    if ((document.Information.amount.value != "") && 
        (document.Information.amount.value != "x")) {

        if (document.Information.LastName.value != "" ||
            document.Information.FirstName.value != "" )  {

                document.addform.submit();
        }
        else { 
            alert("Please enter missing information");
        } 
    }
}

</SCRIPT>





</body>
</html>

This question is an extension of this one:

Calculate order price by date selection value

I'm trying to make a conference registration page based off the previous page, which passes the variables(name, email, price) to my organization's outdated shopping cart using javascript. I'm also using Seminar Registration by CSSTricks (http://css-tricks.com/examples/SeminarRegTutorial/)

Currently, my proceed to payment button produces an 'element is undefined' error on line 298(same thing on unresolved previous question, linked above^):

 switch (document.Information.amount.value) {

Any help would be greatly appreciated. I'm at my wits end with this. Here is the page:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Seminar Registration Form with jQuery</title>

    <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />


    <script src="js/jquery-1.2.6.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/form-fun.jquery.js" type="text/javascript" charset="utf-8"></script>

    <!--[if IE]>
        <style type="text/css">
            legend { 
                position: relative;
                top: -30px;
            }

            fieldset {
                margin: 30px 10px 0 0;
            }
        </style>

        <script type="text/javascript">
            $(function(){
                $("#step_2 legend").css({ opacity: 0.5 });
                $("#step_3 legend").css({ opacity: 0.5 });
            });
        </script>
    <![endif]-->
</head>

<body>


    <div id="page-wrap">

        <h1>MFYC'10 <span>Registration</span></h1>

        <form action="#" name="Information" method="post">

            <fieldset id="step_1">

                <legend>Step 1</legend>

                <label for="num_attendees">
                    How cool are you?
                </label>
                <select id="amount">
                    <option id="0" value="0">Please Choose</option>
                    <option id="prof" value="90.00">Professional</option>
                    <option id="grad" value="55.00">Graduate Student</option>

                </select>

                <br />

                <div id="attendee_1_wrap" class="name_wrap push">
                    <h3>Who are you?</h3>

                    <p>
                    <label for="FirstName">
                            First Name:
                    </label>
                    <input type="text" id="FirstName" class="name_input"></input>
                    </p>

                    <p>
                    <label for="LastName">
                            Last Name:
                    </label>
                    <input type="text" id="LastName" class="name_input"></input>
                    </p>

                    <p>
                    <label for="OfficialTitle">
                            Official Title:
                    </label>
                    <input type="text" id="OfficialTitle" class="name_input"></input>
                    </p>

        <h3>How do we find you?</h3>


                <label for="email">Email: </label>

<input id="email" name="email" class="required email" />
</p>

<p>
<label for="Address">Street Address: </label><input name="Address" id="Address" type="text" size="20" maxlength="75" />
</p>
<p>
<label for="City">City: </label><input name="City" id="City" />
</p>
<p>
<label for="State">State: </label><select name="State" id="State">

<option selected value="IL">IL</option>
    <option value="AL">AL</option>
    <option value="AK">AK</option>
    <option value="AZ">AZ</option>
    <option value="AR">AR</option>
    <option value="CA">CA</option>

    <option value="CO">CO</option>
    <option value="CT">CT</option>
    <option value="DE">DE</option>
    <option value="DC">DC</option>
    <option value="FL">FL</option>
    <option value="GA">GA</option>

    <option value="HI">HI</option>
    <option value="ID">ID</option>
    <option value="IN">IN</option>
    <option value="IA">IA</option>
    <option value="KS">KS</option>
    <option value="KY">KY</option>

    <option value="LA">LA</option>
    <option value="ME">ME</option>
    <option value="MD">MD</option>
    <option value="MA">MA</option>
    <option value="MI">MI</option>
    <option value="MN">MN</option>

    <option value="MS">MS</option>
    <option value="MO">MO</option>
    <option value="MT">MT</option>
    <option value="NE">NE</option>
    <option value="NV">NV</option>
    <option value="NH">NH</option>

    <option value="NJ">NJ</option>
    <option value="NM">NM</option>
    <option value="NY">NY</option>
    <option value="NC">NC</option>
    <option value="ND">ND</option>
    <option value="OH">OH</option>

    <option value="OK">OK</option>
    <option value="OR">OR</option>
    <option value="PA">PA</option>
    <option value="RI">RI</option>
    <option value="SC">SC</option>
    <option value="SD">SD</option>

    <option value="TN">TN</option>
    <option value="TX">TX</option>
    <option value="UT">UT</option>
    <option value="VT">VT</option>
    <option value="VA">VA</option>
    <option value="WA">WA</option>

    <option value="WV">WV</option>
    <option value="WI">WI</option>
    <option value="WY">WY</option>
</select>
</p>
<p>
<label for="Zip">Zip Code: </label><input name="Zip" id="Zip" type="text" value="" size="5" maxlength="10"  />
</p>
<p>
<label for="Phone">Telephone: </label><input name="Phone" id="Phone" type="text" value="" size="10" maxlength="13" />
</p>


                </div>


            </fieldset>

            <fieldset id="step_2">

                <legend>Step 2</legend>

                <p>
                    Do you work in Higher Education?
                </p>


                <input type="radio" id="company_name_toggle_on" name="company_name_toggle_group"></input>
                <label for="company_name_toggle_on">Yes</label>
                 
                <input type="radio" id="company_name_toggle_off" name="company_name_toggle_group"></input>
                <label for="company_name_toggle_off">No</label>

                <div id="company_name_wrap">
                    <label for="company_name">
                        Which School?
                    </label>
                    <input type="text" id="company_name"></input>
                </div>

                <div class="push">          
                    <p>
                        Will anyone in your group require special accommodations?
                    </p>

                    <input type="radio" id="special_accommodations_toggle_on" name="special_accommodations_toggle"></input>
                    <label for="special_accommodations_toggle_on">Yes</label>
                     
                    <input type="radio" id="special_accommodations_toggle_off" name="special_accommodations_toggle"></input>
                    <label for="special_accommodations_toggle_off">No</label>
                </div>
                <div id="special_accommodations_wrap">
                    <label for="special_accomodations_text">
                        Please explain below:
                    </label>
                    <textarea rows="10" cols="10" id="special_accomodations_text"></textarea>
                </div>


            </fieldset>

            <fieldset id="step_3">
                <legend>Step 3</legend>

                <label for="rock">
                    Are you ready to rock?
                </label>
                <input type="checkbox" id="rock"></input>
            <p>
                <INPUT onclick="javascript:PaymentButtonClick()" type=button value="Proceed to payment" name=PaymentButton>

                <img src="images/visa1.gif" />
                <img src="images/mastercard1.gif" />
            </p>

            </fieldset>

        </form>

    </div>

<FORM name="emailForm" action="http://www.its.niu.edu/its/scripts/mailform.asp method=post">

<INPUT type="hidden" value="Conference Registration" name="mf_subject">
<INPUT type="hidden" value="Yes" name="mf_email_results"> 


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="20" name="amount">


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="FirstName">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="22" name="LastName">

<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="64" name="OfficialTitle">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="40" name="email">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="48" name="Address">

<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="City">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="State">
<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="Zip">


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="Phone">

<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffa0" size="17" name="company_name">


<INPUT type="hidden" title="" style="BACKGROUND-COLOR: #ffffff" size="20" name="special_accomodations_text">

<INPUT type="hidden" value="[email protected]" name="mf_from">

<INPUT type="hidden" value="[email protected]" name="mf_to">
</FORM>










<FORM name="addform" action="https://webcluster.niu.edu/CreditCard/servlet/Shopping_Cart_Add_Item_Servlet" method="post">

<INPUT type="hidden" value="orient" name="Dept_ID">
<INPUT type="hidden" value="Orientation" name="Product_Name">
<INPUT type="hidden" value="z000000" name="Product_Code">
<INPUT type="hidden" value="7.00" name="amount">
<INPUT type="hidden" value="/orientation/index.shtml" name="return_link">
<INPUT type="hidden" value="http://www.niu.edu" name="return_server">
<INPUT type="hidden" value="1" name="quantity"> <INPUT type="hidden" value="0" name="tax">
<INPUT type="hidden" value="0" name="ship"> <INPUT type="hidden" value="DQ83225" name="sale_id">
<INPUT type="hidden" value="401200" name="sale_acct">
</FORM>


<SCRIPT language="Javascript"> 

function PaymentButtonClick() {



    document.addform.Product_Name.value = document.Information.FirstName.value + ","+ 
                                          document.Information.LastName.value+","+
                                          document.Information.OfficialTitle.value+","+
                                          document.Information.email.name+","+","+
                                          document.Information.Address.value+ "," + 
                                          document.Information.City.value+ "," + 
                                          document.Information.State.value+ "," + 
                                          document.Information.Zip.value+ "," + 
                                          document.Information.Phone.value+ "," + 
                                          document.Information.company_name.value+ "," + 
                                          document.Information.special_accomodations_text.value;

    document.addform.Product_Code.value = document.Information.LastName.value;


    if ((document.Information.amount.value != "") && 
        (document.Information.amount.value != "x")) {

        if (document.Information.LastName.value != "" ||
            document.Information.FirstName.value != "" )  {

                document.addform.submit();
        }
        else { 
            alert("Please enter missing information");
        } 
    }
}

</SCRIPT>





</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2024-09-05 21:11:41

我做了一些明显的编辑(表单名称等),但我错过了,它会传递到购物车,但是,这一行:

    <INPUT type="hidden" value="" name="amount">

不会显示此处确定的价格:

switch (document.Information.amount.value) {
 case 'prof':
     document.Information.amount.value = 90.00;
     break;
 case 'grad':
     document.Information.amount.value = 55.00;
     break;
}

I made some obvious edits (form name, etc) that I missed and it passes to the shopping cart, however, this line:

    <INPUT type="hidden" value="" name="amount">

won't show the price determined here:

switch (document.Information.amount.value) {
 case 'prof':
     document.Information.amount.value = 90.00;
     break;
 case 'grad':
     document.Information.amount.value = 55.00;
     break;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文