表单未提交动态生成的输入(jQuery) [英] Form not submitting dynamically generated inputs (jQuery)

查看:144
本文介绍了表单未提交动态生成的输入(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在为我的表单动态生成一些输入,但不会发布新的输入生成,到目前为止,我一直在搜索,唯一可以找到的是使该表单直接身体标签的孩子,和我的应用程序的设计是不可能的,所以有人可能会知道会发生什么,如何解决?而不,它不适用于 .live()

Hello I'm trying to dynamically generate some inputs for my form, but it's not posting the new inputs generated, so far I've been searching around and the only thing I was able to find is to make the form a direct children of the body tag, and as in the design of my app thats not possible, so somebody might know what happens and how to solve it? And no, it doesn't work with .live().

HTML

 <form name="order" id="newOrder" action="../core/query.php" method="post">
        <input type="text" value="Search" id="itemSearch" class="search"/>
        <input type="hidden" id="itemAdd"/>
        <button type="button" class="boton" id="additem">Add</button> 
        <br>
        <div id="items"></div>
        <br>
        <button type="submit" class="boton" > Submit</button>
        <button type="reset" class="boton" style="float:right;"> Cancel</button>
        </div>
    </form>

Javascript

  $('#additem').click(function(){
if($('#itemAdd').val()){
    var rawr = $('<div></div>')
    .css('display','none')
    .html(  '<br><table><td>'
            +currItem.label+'</td><td> Size '
            +currItem.size+'</td><td class="right">$'+currItem.price
            +'</td></table> <input type="hidden" name="contents[]" value="'
            +currItem.value+'"/>');
    var mhm = currItem.price;
    rawr.appendTo('#items').toggle(500).click(function(){
        $(this).toggle(500,function(){
            $(this).remove();
        });
        $('#total').fadeOut("fast",function(){
            total = (parseFloat($(this).text())-parseFloat(mhm)).toFixed(2);
            $(this).text(total).fadeIn("fast");
        });
    });
    $('#total').fadeOut("fast",function(){
        total = (parseFloat($(this).text())+parseFloat(mhm)).toFixed(2);
        $(this).text(total).fadeIn("fast");
        currItem=null;
    });
   }
  });

所以基本上我使用jQuery UI自动完成与一个远程JSON,当按 #addItem 按钮创建一个表,其中包含一些文本和隐藏的输入,其中包含数据库中的ID,所有这些表都会正确显示,但是在提交时不会发布或不发布序列化。

So basically I use jQuery UI autocomplete with a remote JSON that when pressing the #addItem button creates a table with some text and a hidden input with an ID from a database, all get displayed correctly, but when submitting they are not posted nor serialized.

推荐答案

可能要做一些调试的时间。你确定没有被POST吗?以下jsFiddle使用您的确切代码,并且在提交表单时,您可以在Firebugs NET选项卡中看到POST值。

Might be time to do some debugging. Are you sure it's not being POSTed? The following jsFiddle uses your exact code, and when the form is submitted, you can see the values being POSTed in Firebugs NET tab.

http://jsfiddle.net/s6Umg/

使用NET检查您的真实示例在Firebug中的标签,以查看值是否实际上通过。也许访问数据一旦发布,就有问题。您如何访问query.php文件中的POST数据?

Check your real example using the NET tab in Firebug to see if the values are actually getting passed through. Perhaps there's a problem accessing the data once it's already been posted. How are you accessing the POST data in your query.php file?

这篇关于表单未提交动态生成的输入(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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