PHP从所选文本框发布值

PHP从所选文本框发布值,php,jquery,html,forms,Php,Jquery,Html,Forms,我正在尝试使用PHP、HTML和jQuery的组合创建一个比较页面/表单。我想创造的理想效果如下 <form> left | right [text1.l] | [text1.r] [text2.l] | [text2.r] submit </form> 左|右 [text1.l]|[text1.r] [text2.l]|[text2.r] 提交 其中,[]表示输入文本框。对于特定的用例,用户sele

我正在尝试使用PHP、HTML和jQuery的组合创建一个比较页面/表单。我想创造的理想效果如下

<form>
    left       |    right
    [text1.l]  |    [text1.r]
    [text2.l]  |    [text2.r]
    submit
</form>

左|右
[text1.l]|[text1.r]
[text2.l]|[text2.r]
提交
其中,
[]
表示输入文本框。对于特定的用例,用户select将为每一行选择左侧或右侧文本框,并发布表单。本质上,我只对处理表单时选择的文本框的值感兴趣

我曾考虑使用单选按钮,因为我只允许每行选择一个框,但我不确定如何设置它来检索文本框值


任何帮助都将不胜感激,干杯。

JSFIDDLE

表格

<form method="post" action="process.php" class="form">
<fieldset id="left">Left
    <input type="text" name="foo-left-1" size="50" />
    <input type="text" name="foo-left-2" size="50" />
</fieldset>
<fieldset id="right">Right
    <input type="text" name="foo-right-1" size="50" />
    <input type="text" name="foo-right-2" size="50" />
</fieldset>
<input type="submit" value="Submit">
</form>
  • 用户通过单击选择文本框

  • 单击“提交”时,浏览器将仅发送未禁用的字段。 $\u POST数组将只包含所有未禁用字段中的值

  • 当用户输入以下内容时: 你会得到
    $\u POST['foo-right-1']='car'
    $\u POST['foo-left-2']='dog'


是的,但是$\u POST['right-article-1']只给我“1”等,而不是与该单选按钮关联的文本框值。这正是我感兴趣的地方。Úsea textarea:-相应地更新了示例代码并添加了一个jsfiddle。这甚至允许用户选择提交左值还是右值?
$("input[type=text], textarea").focus(function(){
    // Check for the change from default value
    if(this.value == this.defaultValue){
        this.select();
    }

    // get the name of the field, e.g. foo-left-1
    //alert(this.name);
    var fieldNameSplitted = this.name.split("-");

    // recombine + switch "left" to "right" and vice versa
    var fieldNameOtherSide = '';

    // the ident remains the same (e.g. foo-)
    var fieldNameOtherSide = fieldNameSplitted[0] + "-";

    // left/right switch (e.g. foo-left, gets foo-right and vv)
    if(fieldNameSplitted[1] == 'left') { fieldNameOtherSide += 'right-'; }
    if(fieldNameSplitted[1] == 'right') { fieldNameOtherSide += 'left-'; }

    // row number (e.g. foo-right-2)
    fieldNameOtherSide += fieldNameSplitted[2];

    // now we have the name of the field on the other side of the row, right?
    //alert(fieldNameOtherSide);

    // use that as jQuery selector and disable the element
    // because  the user has selected the other one
    // and when the form is send disabled fields will not be send
    // http://www.w3.org/TR/html401/interact/forms.html#disabled
    $('input[name=' + fieldNameOtherSide + ']').prop("disabled", true);
});