简体   繁体   English

如何防止可选输入字段的占位符值在离开数据库时进入数据库?

[英]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.

相关问题 防止用户在输入字段中输入大于2位数字的值 - Prevent users from entering a value greater than 2 digits in an input field 如何防止用户在输入字段中输入字符“`”? - How to prevent the user from entering the character "`" in the Input field? 如何防止用户在输入字段中输入无效字符 - How to prevent users from entering invalid characters inside an input field 如何防止用户在 ReactJS 的输入表单字段中输入空格? - How to prevent user from entering spaces in an input form field in ReactJS? 如何防止用户在Vue 3数字输入中输入低于1的值 - How to prevent user from entering value below 1 in Vue 3 number input PHP未将隐藏输入字段的值输入数据库 - PHP not entering value of hidden input field into database 如果一定数量的数字已经具有值,则阻止用户在输入字段中输入数字 - Prevent the user from entering a number in the input field if a certain number of them already have a value 如果 HTML 表单的输入字段值为空,如何防止提交它 - How to prevent submitting the HTML form's input field value if it empty 如果前一个字段为空,如何防止用户输入值? - How to prevent user entering value if previous field is empty? 如何获取在选择2输入字段上输入的当前输入值 - How to get the current input value which is entering on select 2 input field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM