I would like to know the best reverse compatible approach to nullifying the value property in a hidden field using JQuery.
Thanks!
Note:
$('#MyHiddenField').val('');
is not good enough.
I need a good old fasioned null.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t. The
valueproperty always holds a string. If you assign anything to it besides a string, it will be converted to a string.That is because the
HTMLInputElementinterface’svalueproperty is of typeDOMString. Independently of being ahiddeninput or not, the input element interface forces any value set to theinput‘svalueproperty to be of typestring, otherwise it’d render input elements unusable to the end-user – this is the purpose of input elements after all. Also it’d be impossible to make a regularapplication/x-www-form-urlencodedrequest if the input values weren’t strings.You may be looking for something else than a hidden input, but what you can do without major changes in your code is simply checking if the value is an empty string before using it and assigning it to
null:And if you need it for posting to server-side, the operation is the same. Post it as an empty string then check if the posted data is an empty string and assign it to
null.