Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.