Update hidden input value with onclick event from ajax drop down menu(使用 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 事件更新隐藏的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 ajax 下拉菜单中的 onclick 事件更新隐藏的输


基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01