[英]How to check modified form fields in Server side
I am having a form with 700 fields. 我有700个字段的表格。 Suppose if an user updates one or two fields, i want to update that particular fields in Database.
假设如果用户更新一个或两个字段,我想更新数据库中的那个特定字段。 My question is how to find that particular(modified) fields in server side, i dont want to execute update query to all the tables.
我的问题是如何在服务器端找到特定的(修改的)字段,我不想对所有表执行更新查询。 I am using Jboss server, Java, Jsp & MySql
我正在使用Jboss服务器,Java,Jsp和MySql
Try this basic approach: 尝试以下基本方法:
First don't give name
attribute to the fields initially. 首先,首先不要将
name
属性赋予字段。 Now when user edits the fields, using javascript give the name
attribute to the field. 现在,当用户编辑字段时,使用javascript将
name
属性赋予字段。 That is it ! 这就对了 ! On the server side you will always receive data in name=value pair, if there is no
name
the browser won't pass the field value to the server. 在服务器端,您将始终以“名称=值”对的形式接收数据,如果没有
name
,浏览器将不会将字段值传递给服务器。
EDIT: 编辑:
Keep hidden fields with the old values but with no names. 保留具有旧值但没有名称的隐藏字段。 This will help you to test whether user has entered new value or not.
这将帮助您测试用户是否输入了新值。
This is an example: 这是一个例子:
script 脚本
$(function(){
$(document).on('input', '.to-edit', function(e) {
var box = $(this);
var prv = box.prev().val();
var cur = box.val();
if ('' === cur || prv === cur) {
box.prop('name', '');
} else {
box.prop('name', 'txtName');
}
e.stopPropagation();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.