How to use javascript to set text area value in a form in IE
Asked Answered
A

4

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;

Accrue answered 8/4, 2011 at 0:15 Comment(0)
C
15

This should work:

<textarea id="bla">from</textarea>
<script type="text/javascript">
document.getElementById("bla").value = "test";
</script>
Cryohydrate answered 8/4, 2011 at 0:22 Comment(0)
U
3

Try this:

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

Assuming you have:

<form name='submitquestion'>
    <textarea name='selectedtext'></textarea>
</form>
Unbodied answered 8/4, 2011 at 0:23 Comment(0)
M
1

I recommend using JQuery, it works with all browsers.

$('#selectedtext').val('whatever');
Majormajordomo answered 8/4, 2011 at 0:44 Comment(1)
nothing wrong with using jQuery you can get the value by $('#selectedtext').val()Mcshane
D
0

You can do this in pure javascript like this

document.getElementById("myTextarea").value = txt;
Dodiedodo answered 4/12, 2014 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.