If you use jQuery to fetch the current value of a field like

you might encounter issues, even if this syntax is correct. E.g. if a number is entered, it works. If a special char is entered, you might get an empty string.


A possible cause could be the HTML input tag attributes.

This one works not for special characters or letters:

Using a number type, letters stay in the field (optically), but do not seem to be saved as the value indeed, and jQuery seems to consider that.

Use special input types only if you really need them. In the example above, a value like 1234 works, but not ” 1234″ (with a space) or “=1234” or “1+2” etc.

The following should always work:

If you still encounter issues, you might have indeed no value in the input field. Try .html() or .text() for testing purposes.

Share This: