简体   繁体   中英

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. Also I have a text box with placeholder="opt" and id="ext" in my JSP registration page which is an optional field. 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. 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.

Check on servlet like as below:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM