简体   繁体   中英

change maxlength of input text field onblur event

 <h:inputText id="interestrate" value="#{bean.interestrate}" maxlength="5" onblur="convert();"/>

instance= i need to accept maximum 5 digit value(12345) in my input field and convert to float variable with fixed 3.

(12.345)

conversion is done by calling javascript method convert();. But now the field value size is 6 including "."(dot). So how to change the maxlenth of this input field ONBLUR event.

Thank you for posting your code. You can just add this line into your convert() function:

this.setAttribute("maxlength", 6);

Don't do this on blur event, because on blur event the maximum field size will increase to 6 and in this case the user can go back to the previous field and can enter the six digit value which is against your validation.

Change the maximum length of that field on convert() method call.

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