title: Javascript Dictionary problems
body: <p>I am creating a javascript based "favourite assignment" list for my photo app which I have created using phonegap. </p>
  
  <p>I'm basing it on a "to-do list" tutorial code and have tried to adapt it to my purposes.</p>
  
  <p>There are two variables: the title (text) and the link (text2)</p>
  
  <p>It works great in a browser, and on first launch in the app. 
  But on refresh or relaunch, I dont think it's saving the link variable to the dictionary. </p>
  
  <p>would appreciate any guidance with the code:</p>
  
  <pre><code>&lt;script type="text/javascript" language="JavaScript"&gt;
  
      //Create a new To-Do
      function createNewToDo()
      {
          var todoDictionary = {};
          //Prompt the user to enter To-Do
          var todo="FAST SHUTTER SPEEDS";
          var todolink="#fastshutter";
          if (todo!=null)
          {
              if (todo == "")
              {
                  alert("To-Do can't be empty!");
              }
              else
              {
                  //Append the new To-Do with the table
                  todoDictionary = { check : 0 , text : todo , text2 : todolink};
                  addTableRow(todoDictionary,false);
              }
          }
  
      }
  
  
      //Add a row to the table
      var rowID = 0;
      function addTableRow(todoDictionary, appIsLoading)
      {
  
          rowID +=1;
          var table = document.getElementById("dataTable");
          var rowCount = table.rows.length;
          var row = table.insertRow(rowCount);
  
          //Set up the CheckBox
          var cell1 = row.insertCell(0);
          var element1 = document.createElement("input");
          element1.type = "deleteButton";
          element1.value = "X";
  
          element1.setAttribute("onclick","deleteSelectedRow(this)");
          element1.className = "deleteButton";
          cell1.appendChild(element1);
  
  
          //Set up the View Button
          var cell2 = row.insertCell(1);
          var element2 = document.createElement("input");
          element2.type = "viewButton";
          element2.value = todoDictionary["text"];
          var link = todoDictionary["text2"];
          element2.id = rowID;
          element2.onclick=function(){ window.location.hash = link; };
          element2.className = "viewButton";
          cell2.appendChild(element2);
  
          //Save &amp; Update UI
          saveToDoList();
  
          if (!appIsLoading)
          alert("Assignment Added To Favourite List!");
      }
  
  
  
  
      //Deletes current row
      function deleteSelectedRow(deleteButton)
      {
          var p=deleteButton.parentNode.parentNode;
          p.parentNode.removeChild(p);
          saveToDoList();
      }
  
  
  
  
      function saveToDoList()
      {
          //Create a todoArray
          var todoArray = {};
          var checkBoxState = 0;
          var textValue = "";
          var text2Value = "";
  
          //Get current table
          var table = document.getElementById("dataTable");
          var rowCount = table.rows.length;
  
          if (rowCount != 0)
          {
              //Loop through all rows
              for(var i=0; i&lt;rowCount; i++)
              {
                  var row = table.rows[i];
  
                  //Add checkbox state
                  var chkbox = row.cells[0].childNodes[0];
                  if(null != chkbox &amp;&amp; true == chkbox.checked)
                  {
                      checkBoxState = 1;
                  }
                  else
                  {
                      checkBoxState= 0;
                  }
  
  
                  //Add text data
                  var textbox = row.cells[1].childNodes[0];
                  textValue = textbox.value;
  
  
                  //Fill the array with check &amp; text data
                  todoArray["row"+i] =
                  {
                      check : checkBoxState,
                      text : textValue
                  };
  
              }
          }
          else
          {
              todoArray = null;
          }
  
          //Use local storage to persist data
          //We use JSON to preserve objects
  
          window.localStorage.setItem("todoList", JSON.stringify(todoArray));
      }
  
  
  
      function loadToDoList()
      {
  
          //Get the saved To-Do list array by JSON parsing localStorage
          var theList = JSON.parse(window.localStorage.getItem("todoList"));
  
  
          if (null == theList || theList=="null")
          {
              deleteAllRows();
          }
          else
          {
              var count = 0;
              for (var obj in theList)
              {
                  count++;
              }
  
              //Clear table
              deleteAllRows();
              //Loop through all rows
              for(var i=0; i&lt;count; i++)
              {
                  //Add row
                  addTableRow(theList["row"+i],true);
              }
  
          }
  
      }
  </code></pre>