PHP从所选文本框发布值
我正在尝试使用PHP、HTML和jQuery的组合创建一个比较页面/表单。我想创造的理想效果如下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
<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'
$("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);
});