I am trying add to a form dynamically from a table outside the form> have a basic form and then from a summary table the form I want to click an edit button that will add elements to the form. Below is my first attempt on just adding a hidden field. I have a div that the hidden fields are in.
我正在尝试从表单外部的表中动态添加表单>有一个基本表单,然后从摘要表中我想要单击一个编辑按钮,将向表单添加元素。下面是我第一次尝试添加隐藏字段。我有一个隐藏字段所在的div。
Here is the code below. The table I am showing is actually in a scrollable table and div design. I stripped it down to its basic elements for this function.
这是下面的代码。我展示的表实际上是一个可滚动的表和div设计。我把它剥离到了这个功能的基本元素。
<form id="incidentform" action="" method="get">
<div id="hidfielddiv">
<input type="hidden" name="mchnum" value="346"/>
<input type = "hidden" name="mchemploy" value="1"/>
<input type = "hidden" name="persontypeid" id="persontypeid" value="2"/>
</div>
<label class="main">Employee Information</label>
<label class="empname">Name</label>
<label class="empname">Nursing Assistant - 80</label>
<input type="submit" class="button" id="addincidentButton" name="addincidentButton" value="Add Incident"/>
</form>
<table>
<tr>
<td style="display: none;">0</td>
<td style="display: none;">2</td>
<td>11/12/2014</td>
<td>4:04 PM</td>
<td>
<input type="button" class="button" class="editincidentbutton" value="Edit incident" />
</td>
</tr>
</table>
As you can see the table is outside the form and here is the script.
如您所见,表格在表单之外,这是脚本。
$(function(){
$(".editincidentbutton").click(function(){
$('<input>').attr({
type: 'hidden',
id: 'superwitness',
name: 'superwitness',
value: '0'
}).appendto("#hidfielddiv");
}
)
})
3 个解决方案
#1
1
The problem is two-fold
问题是双重的
1) camelcCase the appendTo function - appendTo()
1)camelcCase appendTo函数 - appendTo()
2) you have multiple classes on your button - the first one takes precedence, so remove it <input type="button" class="editincidentbutton" value="Edit incident" />
2)你的按钮上有多个类 - 第一个优先,所以删除它
#2
1
The jQuery function name is appendTo
with "To" capitalized, and Javascript is case-sensitive - you need to change your line of code to:
jQuery函数名称是appendTo,“To”大写,Javascript区分大小写 - 您需要将代码行更改为:
}).appendTo("#hidfielddiv");
#3
0
Two issues. Either do appendTo (case sensitive), or use append and reverse the divs. I wrote it below
两个问题。要么appendTo(区分大小写),要么使用追加和反转div。我在下面写了
$(function(){
$(".editincidentbutton").click(function(){
$('#hidfielddiv').append('<input type="hidden" id="superwitness" name="superwitness" value="0">');
});
});
});
The second issue (important) is that the button you're listening to has two 'class' values. This should be
第二个问题(重要)是您正在收听的按钮有两个“类”值。这应该是
<input type="button" class="button editincidentbutton" value="Edit incident" />
instead of
代替
<input type="button" class="button" class="editincidentbutton" value="Edit incident" />
I tested it and it works, let me know if you have any issues.
我测试了它并且它有效,如果您有任何问题,请告诉我。
#1
1
The problem is two-fold
问题是双重的
1) camelcCase the appendTo function - appendTo()
1)camelcCase appendTo函数 - appendTo()
2) you have multiple classes on your button - the first one takes precedence, so remove it <input type="button" class="editincidentbutton" value="Edit incident" />
2)你的按钮上有多个类 - 第一个优先,所以删除它
#2
1
The jQuery function name is appendTo
with "To" capitalized, and Javascript is case-sensitive - you need to change your line of code to:
jQuery函数名称是appendTo,“To”大写,Javascript区分大小写 - 您需要将代码行更改为:
}).appendTo("#hidfielddiv");
#3
0
Two issues. Either do appendTo (case sensitive), or use append and reverse the divs. I wrote it below
两个问题。要么appendTo(区分大小写),要么使用追加和反转div。我在下面写了
$(function(){
$(".editincidentbutton").click(function(){
$('#hidfielddiv').append('<input type="hidden" id="superwitness" name="superwitness" value="0">');
});
});
});
The second issue (important) is that the button you're listening to has two 'class' values. This should be
第二个问题(重要)是您正在收听的按钮有两个“类”值。这应该是
<input type="button" class="button editincidentbutton" value="Edit incident" />
instead of
代替
<input type="button" class="button" class="editincidentbutton" value="Edit incident" />
I tested it and it works, let me know if you have any issues.
我测试了它并且它有效,如果您有任何问题,请告诉我。