0

I have an order form I'm working on, where I'm using jQuery to update the price in real time when the user selects different options. So, right now, the final project cost, package type, etc are set in jQuery variables, which I need to convert to PHP to insert into the database.

You can easily see the code: http://jsfiddle.net/cadengrant/uddPA/2/

And live preview of working code: http://www.htmlified.com/order-now/

function update_price() {
        var base_cost = base_price;
        var basic_price = base_price;
        var pro_price = base_price;

        jQuery('.packages .selected').each(function(index) {
            base_cost += jQuery(this).data("price");
            basic_price += base_cost;
            pro_price += base_cost + 70;
        });

        jQuery('#markup-pages').each(function(index) {
            var price = Number(jQuery(this).val());
            var packages = jQuery('.packages .selected').data("price");
            var pages = 0;

            jQuery('#packages .selected').each(function(index) {
                if(jQuery(this).hasClass('basic')) {
                    if(packages == 199) {
                        pages = price * 99 - 99;
                    } else if (packages == 189) {
                        pages = price * 94 - 94;
                    } else if (packages == 399) {
                        pages = price * 199 - 199;
                    }
                } else if (jQuery(this).hasClass('pro')) {
                    if(pro_price == 269) {
                        pages = price * 134 - 134;
                    } else if (pro_price == 259) {
                        pages = price * 129 - 129;
                    } else if (pro_price == 469) {
                        pages = price * 234 - 234;
                    }
                }
            });

            base_cost += pages;

            /* Single or plural page text */
            if(price == 1) {
                var markup_pages = "markup page";
            } else {
                var markup_pages = "markup pages";
            }
            jQuery('.markup-pages').text(markup_pages);
        });

        jQuery('#packages .selected').each(function(index) {
            if(jQuery(this).hasClass('pro')) {
                base_cost += 70;
            }
        });

        /* Update Doctype */
        jQuery('input[name=page_doctype]:checked', '#order-form').each(function(index) {
            var basic_doctype_text = "";
            var pro_doctype_text = "";
            if(jQuery(this).hasClass('doctypehtml')) {
                var doctype_text = "W3C Valid HTML5 & CSS3";
            } else if (jQuery(this).hasClass('doctypexhtml')) {
                var doctype_text = "W3C Valid XHTML1 & CSS2";
                basic_doctype_text += " Transitional";
                pro_doctype_text += " Strict";
            }

            jQuery('.doctype-text').html(doctype_text);
            jQuery('.basic-doctype').html(doctype_text + basic_doctype_text);
            jQuery('.pro-doctype').html(doctype_text + pro_doctype_text);
        });

        jQuery('.price').html(base_cost);
        jQuery('.basic-price').html(basic_price);
        jQuery('.pro-price').html(pro_price);
    }

I just need to figure out how to pass those variables (doctype text, basic doctype, pro doctype, base_cost, etc etc) in the JS section to my order.php form, so I can update amount paid, the package type they selected, etc. Any help would be greatly appreciated.

4

2 回答 2

2

您的页面中已经有一个表单。我建议您在此表单中创建隐藏输入以与表单一起提交。前任 :

<input type="hidden" name="base_cost" value="999">

您可以使用 jquery 轻松调整值。将表单提交到 php 页面后,您可以使用以下方法捕获这些值:

$base_cost = $_POST['base_cost'];

但不要忘记清理和验证用户的每一个输入。希望这有助于并原谅我的英语。

于 2013-09-11T04:12:20.867 回答
-1

您正在寻找一种方法来告诉用户的服务器信息?我的朋友,不发送表格,不使用 ajax,会很难:)

如果我正确理解了这个问题,那么当用户触发某些操作时,您希望在客户端更改一些参数。在这种情况下,您可以在页面加载时加载可能的参数,并且当用户触发这些操作时,从已加载的参数中获取新参数。然后,当您发送表单时,您会将所选参数添加到其中。

希望能帮助到你!

于 2013-09-11T04:09:42.457 回答