Skip to content

Instantly share code, notes, and snippets.

@flyingmachine
Created March 14, 2012 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingmachine/2039406 to your computer and use it in GitHub Desktop.
Save flyingmachine/2039406 to your computer and use it in GitHub Desktop.
function addTodo()
{
var a = document.getElementById('list').getElementsByTagName('li')[0].firstChild.nodeValue;
var x=document.getElementById("nameOfItem").value;
if(x.length==""){
alert("Please eneter a ToDo item.");
}
else if(x.length > 200)
{
alert("ToDo cannot be more than 200 characters.");
}
else
{
if (a=="This is my first item to do!!")
{
var o = document.getElementById('list');
var p = document.getElementsByTagName('li')[0];
o.removeChild(p);
}
var newli = document.createElement("li");
newli.innerHTML="<input type='checkbox' name='checkbox' value='checkbox'> "+x
document.getElementById("list").appendChild(newli);
document.getElementById("nameOfItem").value=document.getElementById("nameOfItem").defaultValue;
var cnt = document.getElementById("list").getElementsByTagName("li").length;
document.getElementById("count").value = "Number of items: "+cnt;
}
}
function search()
{
var searchstr = document.getElementById("search").value;
window.open("http://www.google.com/search?q="+searchstr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment