[英]How to prevent an optional input field's placeholder value from entering into the database on leaving it?
I have a JSP registration form in my site. 我的网站上有一个JSP注册表格。 Also I have a text box with
placeholder="opt"
and id="ext"
in my JSP registration page which is an optional field. 另外,我在JSP注册页面中有一个带有
placeholder="opt"
和id="ext"
的文本框,这是一个可选字段。 On clicking submit button the value of placeholder is submitting to the database on leaving the optional field blank. 单击提交按钮后,如果将可选字段保留为空白,则占位符的值将提交到数据库。 But I want to clear the value of text box on leaving it blank.
但是我想清除文本框保留空白的值。 I've tried the below methods.
我尝试了以下方法。 But those methods are not working in my case.
但是这些方法在我的情况下不起作用。
document.getElementById("ext").value="";
document.getElementById("ext").placeholder="";
document.getElementById("ext").setAttribute("placeholder","");
I've also tried the same methods with jQuery. 我也尝试过使用jQuery的相同方法。 That also is not working.
那也不起作用。 Can anybody suggest a solution.
任何人都可以提出解决方案。
You can prevent the value of placeholder entering into DB b having a condition on servlet
(business logic) ie the page handling the DB operations. 您可以防止占位符的值进入对
servlet
(业务逻辑)有条件的DB b,即处理DB操作的页面。
Check on servlet like as below: 检查servlet,如下所示:
if(request.getParameter("<Parameter name Here>").equals("<Plaeholder value>"))
{
// set value of <Parameter name Here> nullhere
// Do insert option here
}
The solution will be valid untill you wil change the placeholder's value. 在您更改占位符的值之前,该解决方案将一直有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.