# Accessing a Textarea that Does Not Have an ID

**URL:** <https://discourse.mozilla.org/t/accessing-a-textarea-that-does-not-have-an-id/32797>\
**Category:** Development\
**Created:** [October 23, 2018, 9:09pm UTC](https://discourse.mozilla.org/t/accessing-a-textarea-that-does-not-have-an-id/32797 "2018-10-23T21:09:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msaroff](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/msaroff/32/20303_2.png) [@msaroff](https://discourse.mozilla.org/u/msaroff)\
**Post date:** [October 23, 2018, 9:09pm UTC](https://discourse.mozilla.org/t/accessing-a-textarea-that-does-not-have-an-id/32797/1 "2018-10-23T21:09:20Z")

</div>

Still working on my project, and actually getting some decent results, and I came across in issue.

The main edit window in phpBB has an ID assigned:

```
<div id="message-box" class="message-box">
     <textarea name="message" id="message" rows="15" cols="76" tabindex="4" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onfocus="initInsertions();" class="inputbox" style="position: relative;"></textarea>
</div>

```

But the quick reply text box at the end of each discussion page does not:

```
<div id="message-box" class="message-box">
      <textarea style="height: 9em;" name="message" rows="7" cols="76" tabindex="3" class="inputbox"></textarea>
</div>

```

This means that the code that I use to access the contents of the text box throws an error, `TypeError: document.getElementById(...) is null`, on the latter form of the box.

This means that I cannot extract the data from the 2nd text box that I need, because it is dependent on the id of an element that does not have an id:

```
let TextBoxID = clickedElement.getAttribute('id');
let FocusInfo = document.activeElement;
let txtcont = document.getElementById(TextBoxID).value; //contents of edit box
let selstart = clickedElement.selectionStart; // index of selectin start
let selend = clickedElement.selectionEnd; //index of selection end
let selcont = txtcont.substring(selstart,selend); // selected text content
let firsttext = txtcont.substring(0,selstart); //stuff before the selection
let lasttext = txtcont.substring(selend); // stuff after the selection

```

Is there an ID hiding somewhere, or can I assign an id to the object on the page if it does not have one?

---

<div class="post-metadata">

**Author:** ![NilkasG](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@NilkasG](https://discourse.mozilla.org/u/NilkasG)\
**Post date:** [October 23, 2018, 9:24pm UTC](https://discourse.mozilla.org/t/accessing-a-textarea-that-does-not-have-an-id/32797/2 "2018-10-23T21:24:25Z")

</div>

You get the `.id` of the element just so you can find the same element by its `.id`.  
Why aren’t you just you using the element straight away?

```auto
let txtcont = clickedElement.value

```

---

<div class="post-metadata">

**Author:** ![msaroff](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/msaroff/32/20303_2.png) [@msaroff](https://discourse.mozilla.org/u/msaroff)\
**Post date:** [October 23, 2018, 9:38pm UTC](https://discourse.mozilla.org/t/accessing-a-textarea-that-does-not-have-an-id/32797/3 "2018-10-23T21:38:55Z")

</div>

D’oh!

I am an imbecile.
