dlebowski Posted February 25, 2010 Share Posted February 25, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193374-onclick-add-to-list-and-display-it/ Share on other sites More sharing options...
KevinM1 Posted February 25, 2010 Share Posted February 25, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/193374-onclick-add-to-list-and-display-it/#findComment-1018115 Share on other sites More sharing options...
dlebowski Posted February 25, 2010 Author Share Posted February 25, 2010 Thanks, man. Quote Link to comment https://forums.phpfreaks.com/topic/193374-onclick-add-to-list-and-display-it/#findComment-1018202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.