从提交的表单中获取值 [英] Get values from submitted form

查看:66
本文介绍了从提交的表单中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的表格:

I have a very simple form:

<form id="toBeTranslatedForm" action="actionpage.php" method="POST" >
        <textarea name="userInput" id="toBeTranslatedTextArea"></textarea>
        <select id="translationOptions">//dynamically filled</select>
        <input type="submit" value="Translate" />
</form>

使用Jquery,我正在检测表单是否已提交:

Using Jquery I am detecting whether the form has been submitted:

function outputTranslated()
{
    $('#toBeTranslatedForm').submit(function() {
        //do stuff
    });
}

如何从上面的表格中获取在文本区域中键入的文本以及在选择框中选择的选项?理想情况下,我想将它们放入数组中.

How do I get the text typed in the text area and the option selected in the select box from the form above? Ideally I would like to put them into an array.

推荐答案

以下是获取价值的方法:

Here is how you can get value:

function outputTranslated() {
    $('#toBeTranslatedForm').submit(function() {
       var textareaval = $('#userInput').val();
       alert(textareaval);
    });
}

您可以通过在上面的代码中的textareaval变量定义之后添加以下行来对选择框进行相同的操作:

You can do the same for selection box by adding this line after the textareaval variable definition in the code above:

var selectval = $('#translationOptions').val();

然后,您可以使用序列化,也可以手动将其放入数组:

Then, you can either use serialise, or you can put it into an array manually:

var a = [textareaval,selectval];

这篇关于从提交的表单中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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