I am writing a small javascript utility that does some numerical calculations. Almost all inputs are true numbers (that is, I do math with them, they are not zip codes or something like that). Some of these numbers are modifiers that must be added to other numbers before calculating. I would like these numbers to be displayed with a caption, with a pointer "in front" if the value is greater than zero. This works fine in Firefox and IE, which do nothing special with number entries. However, Chrome does not allow a plus sign in the input value number, although it parseFloatcan handle it just fine. Right now, my code manually adds the value +to the field value, which causes it to break in Chrome.
Is there a way to make this work in Chrome? Apparently ( generating CSS content before or after the input elements) :beforewill not help me here. Ideally, I would like to keep the type number; if all else fails, I can just use it text, but I rely on attributes min, maxand step.
UPDATE: adding novalidateto the field allows a plus sign, but then Chrome will declare valuean empty line. While checking the element, I see no way to get the displayed value if it is invalid, even with novalidate.
UPDATE: it seems that there is no good way to get the value from an invalid field ( How to get the original value <input type = "number" β field? ). And the check confirms that the attributes min, maxand are stepnot allowed for input[type=text]. If I donβt come up with something else, Iβll probably just give up the plus signs.
source
share