I’m using JavaScript to pull a value out from a hidden field and display it in a textbox. The value in the hidden field is encoded.
For example,
I had a similar problem and solve it using the function encodeURIComponent
from JavaScript (documentation)
For example, in your case if you use:
and
encodeURIComponent($('#hiddenId').attr('value'))
you will get chalk%20%26%20cheese
. Even spaces are kept.
In my case, I had to encode one backslash and this code works perfectly
encodeURIComponent('name/surname')
and I got name%2Fsurname