tags:

views:

63

answers:

2

Hi all

Is it possible to pass a chunk of html content to a hidden field and how would I do this?

Thanks

Jonathan

+1  A: 

You could do this with Javascript:

<input type="hidden" id="htmlCodes" />
document.getElementById("htmlCodes").value = "<strong>Hello World</strong>";

Just be sure that your values are properly-escaped when you pass them into the hidden form field.

Online Demo: http://jsbin.com/ubofu/edit

Jonathan Sampson
+1  A: 

Yes - simply HTML encode the content (e.g. replace "<" with "&lt" etc...)

You didn't specify which language you'll use for poplulating the field value, so I can't help with details of how to encode.

Here's a reference of how to do it in jQuery.

Here's Java

DVK
thanks - very much appreciated
Jonathan Lyon
OK - define irony... 3 hours after I answeed this, I had an urgent ticket which ended up being caused by a legacy bug whose origin was - guess it - need to HTML encode strings :)
DVK