Encoding hidden variable

Hi I need some help please,I have hidden field and the value for this, is came from the return of my ajax, example of the returned value from success is A-001…Now how can I make this values not to be view as plain text ?. I don’t know how to encode this in javascript.

Thank you in advance.

if your AJAX returns this value then it already is “encoded in JS” since the AJAX code executes in JS.

Ok thanks,My bad I did not think that I can encode this first in my serverside.

Thank you.

well, JavaScript can handle strings pretty well …

You can’t - anyone can view the source of the page and see what it contains. However you ‘encode’ it the encoded value will still be able to be seen (and reused later if they want to).

Thank you for the reply felgall,even I used base64 ? they can still get the exact value ?

In that case the exact value would be whatever you output in base64. As the form will be set up to expect that value they will be able to copy and reuse it.

so how can I protect the hidden value in form ?

Add the value AFTER the form is submitted

I could not figure it out how to do that adding it after submitting the form.

As you are using an Ajax call to retrieve the value from the server you already have the code on the server to generate the value - you just need to call it at the start of the server side form processing.

I never try this kind of technique before…Ok I will try…

Thank you .

Hi felgall,I am confuse before I can have the value for my hidden field…I have 2 ajax request first to do before I can have the exact value for my hidden field,this exact value is depending on the first and second request and what is being returned.

Thank you in advance.

If you set it on the server after submitting the form then you don’t need the Ajax requests. All they are doing is getting values from the server. Once the form data is on the server you can get those values directly without Ajax to perform the same calculation…

You would need to do that anyway for the small percentage of users with JavaScript turned off.

Thank you for the quick reply :smile:
I will try to change my code.