views:

39

answers:

2

I have a text area with some text. I also have an "onsubmit" event handler. In that I have an alert of the text area's innerHTML and I get back the text that is inside of the textarea. I then try to assign this to the "value" attribute of a hidden input element. However the value is never assigned, when the form posts, the hidden element has no value.

I've even tried something like this

hiddenElement.value = "please work " + textarea.innerHTML;

and that doesn't work either, however when I do this and submit the form, the form handler (a jsp page) shows that "please work" was received as the hidden input.

I've also checked firebug and the hidden element only ever submits "please work" and not the innerHTML of the text area.

What am I missing?

+6  A: 

Is there a reason you're trying to use innerHTML with the textarea? Just use the value property, which will get you whatever text is in the textarea.

casablanca
I tried that and it actually wasn't getting me the right value. The text area is being made into a diji.Editor element, and the HTML code produced from it is held in the text area's innerHTML property
ferrari fan
Nevermind... I could have sworn I had already tried with the value, but when you made the comment I went and tried again. Have to wait 9 mins to accept your answer though
ferrari fan
I just checked the docs for [dijit.Editor](http://api.dojotoolkit.org/jsdoc/1.3.2/dijit._editor.RichText): it says "Do not use this widget with an HTML <TEXTAREA> tag, since the browser unescapes XML escape characters, like <". That *might* be causing problems.
casablanca
+2  A: 

Try:

hiddenElement.value = "please work " + textarea.value;

Although why you wouldn't just use the content of the textarea directly (name it and submit it with the form) is beyond me. The value of a textarea is what you actually want to display, this isn't the right place for innerHTML.

Rudu