To Do List in JavaScript/HTML -


I have prepared the list to do this and almost everything is working right. However, if I delete everything in the list, it will not add me a new entry and I can not seem to know why

Thanks very much for any help.

  & lt; Head & gt; & Lt; Script type = "text / javascript" & gt; / * & Lt ;! [CDATA [* / function addTask () {if (document.forms [0] .newtask.value == "") window.alert ("You must enter a value in the new workspace."); Else {if (document.forms [0] .task option [0] .value == "work") document.forms [0]. Tasks.options [0] = null; Var newTask = new option (); NewTask.value = document.forms [0] .newtask.value; NewTask.text = document.forms [0] .newtask.value; Var numTasks = document.forms [0]. Tasks. Options.length; Document.forms [0]. Tasks. Option [numTasks] = newTask; Document.forms [0] .newtask.value = ""; }} Function deleteTask () {var selectedTask = 0; Var WorkSocial = False; While (Selected Tasks & lt; document.forms [0] .tasks.length) {if (document.forms [0] .task option [selectedTask]. Selected == true) {taskSelected = true; break; } ++ selected tasks; } If (works == true) document.forms [0]. Tasks.options [selectedTask] = null; And window. Alert ("You must select a task in the list."); } Function ascendingSort () {var newTasks = new array (); (Var i = 0; i & lt; document.forms [0]. Task length; ++ i) {new task [i] = document.forms [0]. Tasks. Option [i] .value; } NewTasks.sort (); (Var j = 0; j & lt; document.forms [0] .tasks.length; ++ j) {document.forms [0]. Tasks. Option [j] .value = newTasks [j]; Document.forms [0]. Tasks. Option [j] .text = newTasks [j]; }} / *]] & Gt; * / & Lt; / Script & gt; & Lt; Title & gt; To Do List & lt; / Title & gt; & Lt; / Head & gt;  
  & lt; Body & gt; & Lt; H1 & gt; To Do List & lt; / H1> & Lt; Form action = "" & gt; & Lt; P & gt; New Job & lt; Input type = "article" size = "68" name = "new task" /> & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "button" value = "add task" onclick = "addTask ()" style = "width: 150px" /> & Lt; Input type = "button" value = "delete selected action" onclick = "deleteTask ()" style = "width: 150px" /> & Lt; Br / & gt; & Lt; Input type = "button" value = "ascending sort" onclick = "ascending order" style = "width: 150px" /> & Lt; / P & gt; & Lt; P & gt; & Lt; Select Name = "Work" size = "10" style = "width: 500px" & gt; & Lt; Option value = "task" & gt; Work & lt; / Options & gt; & Lt; / Select & gt; & Lt; / P & gt; & Lt; / Form & gt; & Lt; / Body & gt;  

, Then empty with select , with any options .

With your addTask function

  document.forms [0]. Tasks. Options.length & gt; 0  

Something like this:

  if (document.forms [0] .task options.length & gt; 0and document document [0] .task option. [0] .value == "work") document.forms [0]. Tasks. Option [0] = null;  

View


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -