0

I'm fairly new to javascript and I'm having great trouble making a 'To Do' list in an app I'm developing. At the moment you can type in the text field and click submit which will bring up what you typed along with a checkbox next to it. That's all fine and good, but if I add anything else to do it the previous text and checkbox is overwritten and I can't figure out how add to the list.

Any help would be greatly appreciated!

Html:

Enter What To Do <input id='userInput' size=60>
<button onClick='userSubmit()'>Submit</button>
<BR><P>
<div id='result'></div>

JS:

function userSubmit() {
    var UI=document.getElementById('userInput').value;
    document.getElementById('result').innerHTML='<input type="checkbox">' + UI;
} 
3
  • Are you averse to using Jquery? Commented Jan 31, 2014 at 11:57
  • Not at all! I'm just not sure how to go about it Commented Jan 31, 2014 at 11:59
  • There is no error as such, it works fine! I just want to know how to add to what I put, for example. If I type 1, then submit, then 2, then submit. I want it to display like 1, then 2 underneath it Commented Jan 31, 2014 at 12:04

2 Answers 2

3

Try this:

document.getElementById('result').innerHTML+='<input type="checkbox"> '+UI+'<br>';
Sign up to request clarification or add additional context in comments.

6 Comments

@Praveen; for first time it wont't but later it will append the new entry
@Praveen u missed the "+" operator in ur fiddle code :)
My bad, only through this comment I understood OP's question fully. +1 I will revert my comments.
That works great thanks so much! Now, is there a way to it to display vertically? and Also have a delete icon? or is that calling upon much more JS ?
look at the end of line; der is a "<br>" tag dat will display vertically
|
0
<script type='text/javascript'>
  function userSubmit() {
      var UI=document.getElementById('userInput').value;
      document.getElementById('result').appendChild('<p><input type="checkbox"> '+UI+'</input></p>);
  } 
</script>

3 Comments

That isn't working for me, nothing comes up when I click submit
@user1708762: you forgot to close the bracket
@user3236263 sorry man! i forgot to close one bracket. Try it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.