# \[SOLVED\] Accessing html elements defined into .html file?

**URL:** <https://discourse.processing.org/t/solved-accessing-html-elements-defined-into-html-file/2701>\
**Category:** Coding Questions\
**Created:** [August 16, 2018, 8:18pm UTC](https://discourse.processing.org/t/solved-accessing-html-elements-defined-into-html-file/2701 "2018-08-16T20:18:55Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mloiz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mloiz/32/11462_2.png) [@mloiz](https://discourse.processing.org/u/mloiz)\
**Post date:** [August 21, 2018, 8:56am UTC](https://discourse.processing.org/t/solved-accessing-html-elements-defined-into-html-file/2701/3 "2018-08-21T08:56:51Z")

</div>

Great, thank you, it helped me.  
I added a html submit button associated with a `function()` : it behaves more like a formular now.  
and I added a `createDiv` so that the data can also be retrieve in html.

- code

```auto
<!DOCTYPE html>
<head>
  <meta charset="UTF-8">

  <script defer src=https://cdn.JsDelivr.net/npm/p5></script>
  <script defer src=https://cdn.JsDelivr.net/npm/p5/lib/addons/p5.dom.min.js> </script> 
  <script language="javascript" type="text/javascript">
  
  var canvas, txt, txtData;

  function setup() {
    canvas = createCanvas(300, 100);
    canvas.position(300, 50);    
  }

  function showData(){
    txtData = select("#txtData").value();
    removeElements(); 
    txt = createDiv(txtData);
    txt.position(20,50);
  }

  function draw(){
    background(200);
    text(txtData, 10, 20);
  }

  </script>
</head>
<body>
   <input id="txtData" type="text" placeholder="Enter here some text" />
   <input type="submit" value="Submit" onclick="showData()">
   <hr style="margin-bottom: 20px;">
</body>
</html>

```

- Result

![Screenshot_2018-08-21%20Screenshot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f902be737fa22d38c2d0f95d289986bc264e99f2.png)

---

_[View the full topic](https://discourse.processing.org/t/solved-accessing-html-elements-defined-into-html-file/2701)._
