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

查看:10
本文介绍了使用 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="">

我集成了一个允许触发 onclick 事件的 ajax 下拉菜单.我希望上面的隐藏字段在 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-priceef 属性中获取值.

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天全站免登陆