使用来自ajax下拉菜单的onclick事件更新隐藏的输入值 [英] Update hidden input value with onclick event from ajax drop down menu

查看:67
本文介绍了使用来自ajax下拉菜单的onclick事件更新隐藏的输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MachForm并且已经添加了这个隐藏的字段:

I'm working with MachForm and have this hidden field that I've added:

<input type="hidden" name="element_273_price" value="">

我集成了一个ajax下拉菜单,允许触发onclick事件。我希望上面的隐藏字段在onclick事件之后输入一个值(onclick将告诉隐藏字段该项目是什么以及该项目的价格),以便我可以将其传递给其余的JavaScript用于更新屏幕上的价格。

I've integrated an ajax drop down menu that allows for an onclick event to be fired. I'd like the hidden field above to have a value inputted after the onclick event (onclick would tell the hidden field what the item was and price for that item) so that I can then pass it along through the rest of the JavaScript for the updating of the price on screen.

这是我计算文本框的代码:

Here's my code for calculating a text box:

        $('#main_body li[data-pricefield="text"]').delegate('input.text','keyup mouseout change', function(e) {
        var temp = $(this).attr("id").split('_');
        var element_id = temp[1];
        var ordered = (document.getElementById("element_" + element_id).value);
        var price = $(this).data('pricedef');

        var price_value = price * ordered;
        price_value = parseFloat(price_value);
        if(isNaN(price_value)){
            price_value = 0;
        }

        $("#li_" + element_id).data("pricevalue",price_value);
        calculate_total_payment();
    }); 


推荐答案

尝试输入你的php文件:

Try to put in your php file:

'onlick' => '$("element_'.$yourelementid.'_price").val("'.$data['price'].'");'

然后你将在你的javascript中获取此隐藏输入的值,而不是数量输入的data-pricedef属性。

Then you'll have in your javascript to get the value from this hidden input instead of the data-pricedef attribute of your "Quantity" input.

如果我不明白你的问题,请纠正我。我尝试回复您在视频中显示的代码。

Correct me if I do not understand your problem. I tried to reply from the code you showed in your video.

这篇关于使用来自ajax下拉菜单的onclick事件更新隐藏的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆