Jump to content

phbk

Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral

About phbk

  • Rank
    Newbie
  1. yes sorry, Javascript, thanks I ended giving up to implement the X at the end of each line, to remove that line, but I can't get it to work. If you could help with that as well, I will really appriciate it, if not, no problem, you allready helped me plenty I can still remove by typing the name of the item that needs to get removed
  2. omg, thank you so much, I now see my error, Java need to know that it's addItem (water), and not just "Water" You have helped me alot to understand Java better, Thank you so much for your time. I am very happy with your reply I just testet it, and it works as a charm Thank you again, I might have more questiongs, but if it's not related to this, and I cannot find a solution, I'll make a new tread of course. You have a good way of explaining, and you removed my headache
  3. ok, I have used your input and have a working version. However, 2 questions: Is there any way to rewrite java code so I don't need to add 1 java chapter for every button? I mean function addWater() , function addMilk() etc. Secondly, what is the code to add the Remove item ( the x ) et the end of each line, automatically? Sorry, i guess my question is simple and obvious, but I fail to get it to work as intended. Here is the code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Dynamically add/remove items from list - JavaScript</title> </head> <body> <input type="text" id="candidate"/> <button onclick="addItem()">add item</button> <button onclick="removeItem()">remove item</button> <button onclick="addWater()">Water</button> <button onclick="addMilk()">Milk</button> <ul id="dynamic-list"></ul> <script src="script.js"></script> </body> </html> and my script.js : function addItem(){ var ul = document.getElementById("dynamic-list"); var candidate = document.getElementById("candidate"); var li = document.createElement("li"); li.setAttribute('id',candidate.value); li.appendChild(document.createTextNode(candidate.value)); ul.appendChild(li); } function removeItem(){ var ul = document.getElementById("dynamic-list"); var candidate = document.getElementById("candidate"); var item = document.getElementById(candidate.value); ul.removeChild(item); } function addWater() { var node = document.createElement("LI"); var textnode = document.createTextNode("Water"); node.appendChild(textnode); document.getElementById("dynamic-list").appendChild(node); } function addMilk() { var node = document.createElement("LI"); var textnode = document.createTextNode("Milk"); node.appendChild(textnode); document.getElementById("dynamic-list").appendChild(node); }
  4. Hi Jutsomeguy. Thank you, ill try that. I am unfortunately not too good at Java, but every experience makes it better Thanks
  5. Noone have a solution to this?
  6. Hi. I have tried to evolve on the beautiful script: https://www.w3schools.com/howto/howto_js_todolist.asp Lets say it's a shopping list. How do I add static buttons, preferrably in a left column, so when I click Milk, Milk will appear on the list. I like that I can write what's needed in the textfield, but I like an option to click buttons, instead of writing eg. Sugar, Milk, Potatoes etc. Then I could have a list of buttons to the left, where I can click the buttons, and add text to list. And if possible, it would be awesome to click a button, and copy all in the list to clipboard, ort present the list in a new window or iframe. I have tried to re-use the html part, but adding buttons instead, with value of eg. "Sugar" but it keep saying I need to write something, and when I do, it still won't add Sugar to the list. What am I doing wrong? Can someone help me out? My understanding in Java is very very limited, css somewhat ok and html better. Still cannot work this thing out. I thank you in advance.
×
×
  • Create New...