Jump to content

onclick() add to list and display it


dlebowski

Recommended Posts

For some reason I am having a hard time finding a good resource on the internet that shows me out to use javascript to display a list of strings submitted using an input field. 

 

For example I have this:

<input type="text"><input type="submit" value="click to add" onclick="dostuff()">
<div id=displaydatahere>

 

I just need to know how I display each item entered into the text field like this in a list:

 

item1

item2

item3

Link to comment
https://forums.phpfreaks.com/topic/193374-onclick-add-to-list-and-display-it/
Share on other sites

For some reason I am having a hard time finding a good resource on the internet that shows me out to use javascript to display a list of strings submitted using an input field. 

 

For example I have this:

<input type="text"><input type="submit" value="click to add" onclick="dostuff()">
<div id=displaydatahere>

 

I just need to know how I display each item entered into the text field like this in a list:

 

item1

item2

item3

 

Try:

 

<!DOCTYPE html>
<html>
   <head></head>

   <body>
      <input id="dataInput" type="text" /> <button id="addData" type="button">Click to add data to the list below</button>
      <br />
      <div id="display"></div>
   </body>

   <script type="text/javascript">
      var oButton = document.getElementById('addData');
      var data = document.getElementById('dataInput');
      var display = document.getElementById('display');

      oButton.onclick = function() {
         display.innerHTML += data.value + "<br />";
      }
   </script>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.