使用网格结果填充表单
我需要帮助以正确的方式使用编辑结果填充表单。
我正在使用 flexigrid 并拥有从行中获取详细信息并将其保存在变量中的代码。
我陷入困境的一点是,我还有一个表单,我希望显示这些详细信息以供编辑。结果位于 var 'columns' 中。对于我的一生,我找不到办法做到这一点。
一旦结果出现在表单中,jQuery 就会将这些结果传递给数据库进行处理。
我有所有代码,但不确定要发布哪一部分以引起您的注意。如果有人能够根据我愿意在此处展示的代码(如果可能的话)向我展示如何执行此操作,我将不胜感激。
这用于从网格收集数据:
function editbox(com, grid) {
if (com == 'Edit') {
if ($('.trSelected').length > 0) {
var items = $('.trSelected');
var itemlist = '';
for (i = 0; i < items.length; i++) {
itemlist += items[i].id.substr(3);
}
var id = $("tr.trSelected td:nth-child(1) div").text();
var location = $("tr.trSelected td:nth-child(2) div").text();
var customer = $("tr.trSelected td:nth-child(3) div").text();
var address = ($("tr.trSelected td:nth-child(4) select :selected").text() == "Select an Address") ? "" : $("tr.trSelected td:nth-child(4) select :selected").text();
var service = ($("tr.trSelected td:nth-child(5) select :selected").text() == "Select a Service") ? "" : $("tr.trSelected td:nth-child(5) select :selected").text();
var department = $("tr.trSelected td:nth-child(6) div").text();
var status = $("tr.trSelected td:nth-child(7) div").text();
var custref = $("tr.trSelected td:nth-child(8) div").text();
var size = $("tr.trSelected td:nth-child(9) div").text();
var authorisation = $("tr.trSelected td:nth-child(10) div").text();
var intakedate = $("tr.trSelected td:nth-child(11) div").text();
var destroydate = $("tr.trSelected td:nth-child(12) div").text();
var columns = "id=" + id +
"&location=" + location +
"&customer =" + customer +
"&address=" + address +
"&service=" + service +
"&department=" + department +
"&status=" + status +
"&custref=" + custref +
"&size=" + size +
"&authorisation=" + authorisation +
"&intake_date=" + intakedate +
"&destroy_date=" + destroydate;
console.log(columns);
$("#boxeditform").dialog('open');
//console.log(department+" "+custref+" "+address);
} else {
jAlert('you must select a row');
}
}
}
HTML 用于捕获数据:
<form id="EB_edit" name="EB_edit" action="" method="post" class="webform">
<label for="EB_status">Status:</label>
<select name="EB_status">
<option SELECTED VALUE="">Select a Status</option>
<option value="In">In</option>
<option value="Out">Out</option>
<option value="Destroyed">Destroyed</option>
<option value="Permanent">Permanent</option>
</select><br /><br />
<input id="EB_id" name="EB_id" type="hidden" value="" />
<label for="EB_custref">Box Reference #:</label>
<input id="EB_custref" name="EB_custref" type="text" class="text ui-widget-content ui-corner-all inputbox EB_custref" value="" />
<label for="EB_address">Address:</label>
<input id="EB_address" name="EB_address" type="text" class="text ui-widget-content ui-corner-all inputbox EB_address" value="" />
<label for="EB_service">Service:</label>
<input id="EB_service" name="EB_service" type="text" class="text ui-widget-content ui-corner-all inputbox EB_service" value="" />
<label for="EB_dept">Department:</label>
<input id="EB_dept" name="EB_dept" type="text" class="text ui-widget-content ui-corner-all inputbox EB_dept" value="" />
<div id="f2"></div><br />
<button id="EB_submit" class="submit">Submit</button>
</form>
目的是使用来自 editbox() var 'columns' 的数据填充表单。
I would like help in the correct way to populate a form with results for edit.
I am using flexigrid and have code that gets the details from a row and saves them in variables.
The point where I am stuck, is that I also have a form that I would like these details displayed for edit. The results are in the var 'columns'. For the life of me, I cannot see a way to do it.
Once the results are in the form, jQuery would then pass these results to db for processing.
I have all the code, but not sure what piece to post for your attention. I would be grateful if someone could show me how to do this based if possible on my code which I am willing to show here.
This is used to collect data from grid:
function editbox(com, grid) {
if (com == 'Edit') {
if ($('.trSelected').length > 0) {
var items = $('.trSelected');
var itemlist = '';
for (i = 0; i < items.length; i++) {
itemlist += items[i].id.substr(3);
}
var id = $("tr.trSelected td:nth-child(1) div").text();
var location = $("tr.trSelected td:nth-child(2) div").text();
var customer = $("tr.trSelected td:nth-child(3) div").text();
var address = ($("tr.trSelected td:nth-child(4) select :selected").text() == "Select an Address") ? "" : $("tr.trSelected td:nth-child(4) select :selected").text();
var service = ($("tr.trSelected td:nth-child(5) select :selected").text() == "Select a Service") ? "" : $("tr.trSelected td:nth-child(5) select :selected").text();
var department = $("tr.trSelected td:nth-child(6) div").text();
var status = $("tr.trSelected td:nth-child(7) div").text();
var custref = $("tr.trSelected td:nth-child(8) div").text();
var size = $("tr.trSelected td:nth-child(9) div").text();
var authorisation = $("tr.trSelected td:nth-child(10) div").text();
var intakedate = $("tr.trSelected td:nth-child(11) div").text();
var destroydate = $("tr.trSelected td:nth-child(12) div").text();
var columns = "id=" + id +
"&location=" + location +
"&customer =" + customer +
"&address=" + address +
"&service=" + service +
"&department=" + department +
"&status=" + status +
"&custref=" + custref +
"&size=" + size +
"&authorisation=" + authorisation +
"&intake_date=" + intakedate +
"&destroy_date=" + destroydate;
console.log(columns);
$("#boxeditform").dialog('open');
//console.log(department+" "+custref+" "+address);
} else {
jAlert('you must select a row');
}
}
}
HTML for to capture data:
<form id="EB_edit" name="EB_edit" action="" method="post" class="webform">
<label for="EB_status">Status:</label>
<select name="EB_status">
<option SELECTED VALUE="">Select a Status</option>
<option value="In">In</option>
<option value="Out">Out</option>
<option value="Destroyed">Destroyed</option>
<option value="Permanent">Permanent</option>
</select><br /><br />
<input id="EB_id" name="EB_id" type="hidden" value="" />
<label for="EB_custref">Box Reference #:</label>
<input id="EB_custref" name="EB_custref" type="text" class="text ui-widget-content ui-corner-all inputbox EB_custref" value="" />
<label for="EB_address">Address:</label>
<input id="EB_address" name="EB_address" type="text" class="text ui-widget-content ui-corner-all inputbox EB_address" value="" />
<label for="EB_service">Service:</label>
<input id="EB_service" name="EB_service" type="text" class="text ui-widget-content ui-corner-all inputbox EB_service" value="" />
<label for="EB_dept">Department:</label>
<input id="EB_dept" name="EB_dept" type="text" class="text ui-widget-content ui-corner-all inputbox EB_dept" value="" />
<div id="f2"></div><br />
<button id="EB_submit" class="submit">Submit</button>
</form>
The aim is to populate form with data from editbox() var 'columns'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太了解 Flexigrid,但一定有更好的方法!
与其设置所有这些变量,为什么不创建一个映射并使用它来填充表单呢?
尝试这样的事情:
请注意,
val()
会智能地从<选择>
控件。I'm not up to speed on Flexigrid, but there's got to be a better way!
Rather than setting all those vars, why not create a mapping and use that to populate the form?
Try something like this:
Note that
val()
intelligently fetches the selected value from<select>
controls.