5

I can use this to set a text area (selectedtext) value in a form (submitquestion) if Firefox, but it fails in IE.

document.submitquestion.selectedtext.value = txt;

user570494
  • 557
  • 3
  • 8
  • 14

4 Answers4

15

This should work:

<textarea id="bla">from</textarea>
<script type="text/javascript">
document.getElementById("bla").value = "test";
</script>
ysrb
  • 6,693
  • 2
  • 29
  • 30
3

Try this:

document.forms['submitquestion'].elements['selectedtext'].value = txt;

Assuming you have:

<form name='submitquestion'>
    <textarea name='selectedtext'></textarea>
</form>
moe
  • 28,814
  • 4
  • 19
  • 16
1

I recommend using JQuery, it works with all browsers.

$('#selectedtext').val('whatever');
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
0

You can do this in pure javascript like this

document.getElementById("myTextarea").value = txt;
Smith
  • 5,765
  • 17
  • 102
  • 161