# How transform a value into a html element in p5?

**URL:** <https://discourse.processing.org/t/how-transform-a-value-into-a-html-element-in-p5/33050>\
**Category:** Coding Questions\
**Created:** [October 24, 2021, 10:42pm UTC](https://discourse.processing.org/t/how-transform-a-value-into-a-html-element-in-p5/33050 "2021-10-24T22:42:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![letlet](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@letlet](https://discourse.processing.org/u/letlet)\
**Post date:** [October 24, 2021, 10:42pm UTC](https://discourse.processing.org/t/how-transform-a-value-into-a-html-element-in-p5/33050/1 "2021-10-24T22:42:04Z")

</div>

Hi! I’m trying to make a single web page with p5.js, but at some moment I create an input and the value of the input I want to transform into a html tag (more specifically ‘h3’). I already tried the “.html()” as this example: [[examples | p5.js](https://p5js.org/examples/dom-input-and-button.html)], but for some reason this doesn’t work in my context. I’ll let my code below:

```auto
let inputName, bttName, yourName;

function setup() {
let inputDiv = createDiv();
  inputDiv.id("input-section");
  inputDiv.parent("sobre");

  inputName = createInput();
  inputName.addClass("input-name");
  inputName.parent("input-section");

  bttName = createButton('enter');
  bttName.addClass('btt-name');
  bttName.parent("input-section");
  bttName.mousePressed(sendName);

}

function sendName() {
  let userName = inputName.value();
  yourName.html(userName);
}

```

I need this in as a variable, because after I’ll format it inside a div in css. Is there another way to transform this value?

Thanks

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 25, 2021, 12:44am UTC](https://discourse.processing.org/t/how-transform-a-value-into-a-html-element-in-p5/33050/2 "2021-10-25T00:44:44Z")

</div>

> [@letlet](#):
>
> … the value of the input I want to transform into a html tag (more specifically ‘h3’).

> **[reference | p5.js](https://p5js.org/reference/#/p5/createElement)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

---

<div class="post-metadata">

**Author:** ![letlet](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@letlet](https://discourse.processing.org/u/letlet)\
**Post date:** [October 25, 2021, 11:55am UTC](https://discourse.processing.org/t/how-transform-a-value-into-a-html-element-in-p5/33050/3 "2021-10-25T11:55:47Z")

</div>

Doesn’t work too. 🙁

```auto
function sendName() {
  let userName = inputName.value();
  yourName.createElement('h3', userName);
}

```

Error:

> TypeError: Cannot read properties of undefined (reading ‘createElement’)

I really don’t understand why both get errors, if even I used before at the same code…

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 25, 2021, 12:33pm UTC](https://discourse.processing.org/t/how-transform-a-value-into-a-html-element-in-p5/33050/4 "2021-10-25T12:33:28Z")

</div>

> [@letlet](#):
>
> TypeError: Cannot read properties of undefined

If you get that error it means you’re probably using a var which still doesn’t have a value assigned to it.

Besides, **createElement()** is a method from class p5, which represents the sketch itself.

So you just invoke it directly just like you did w/ **createDiv()**, **createInput()** & **createButton()**.

---

<div class="post-metadata">

**Author:** ![letlet](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@letlet](https://discourse.processing.org/u/letlet)\
**Post date:** [October 25, 2021, 7:11pm UTC](https://discourse.processing.org/t/how-transform-a-value-into-a-html-element-in-p5/33050/5 "2021-10-25T19:11:45Z")

</div>

I get it!!! Thankssss
