找到所有文本框值并发布到PHP MySQL中

时间:2011-12-06 07:27:50

标签: php javascript jquery invoice accounts

我只是jQuery的新手可以帮助我吗?

我想创建一个像this one

这样的发票系统

我需要做的就是添加一个提交按钮,它将起到像这样的功能

的作用

。查找由某个唯一ID

标识的所有textareas输入

然后将这些值发布到php MySQl earch行将包含unqiue数据。

2 个答案:

答案 0 :(得分:0)

你问题中的歧义无论如何这将为你提供所有文本框的值数组

        $(document).ready(function(){
$('#somebuttonid').click(function(){
        var tbarray = new Array();
        $('.yourtextboxclass').each(function(){
        tbarray.push($(this).val()); //You will have a array tbarray with all the values of textboxes
        }):
        $('#somehiddenelementid').val(tbarray);
        $('#somehiddenelementidcontainingform').submit(); //Make sure your action is set,you can access like $_post['$somehiddenelmentname'];
        });
});

    <!--html side-->
    <form id="somehiddenelementidcontainingform" action="youraction" method="post">
    <input type="hidden" name="somehiddenelmentname[]" id="somehiddenelementid" />
    </form>

答案 1 :(得分:0)

我很惊讶地发现用这种方式表达的这个功能并没有带回很多明显答案的帖子。

Amanullah,很多评论都要求你先尝试自己,因为人们通常不喜欢回答谷歌的问题。

我打算推荐相同的内容,但是当我使用您的关键字进行搜索时,没有明显的答案。

要序列化所有输入元素,您可以使用:

$('form :input').serialize() //创建一个查询字符串tb1 = bob&amp; tb2 = smith

$('form :input').serializeArray() //创建一个JSON对象[{name:“tb1”,value:“bob},{name:”tb2“,value:”smith“}]

请注意,那些按元素NAME而不是ID。序列化值后,可以将它们发送到服务器。如果您只想抓取文本框,请将选择器更改为$('form :input:text')

相关问题