javascript

Function Not Running When Called


I have run into what I think is a rather simple problem, but cannot see the error. I have two functions that I am trying to call (one to display the date and another get focus on a text input box). When I run the web page nothing happens, so I am stumped.

I have created a fiddle here: http://jsfiddle.net/dk9D9/

And this is the specific javascript that I am working with.

var $ = function(id) { return document.getElementById(id); };

function todayTxt() {
   var today = new Date();
   return today.getMonth() + 1 + "-" + today.getDate() + "-" + today.getFullYear();
}

var initForm = function ()
{
    document.getElementById('qty1').focus()
}

window.onload = function () {
    $(initForm);
    $(todayTxt);
}

Any help is greatly appreciated.


Solution

  • Seems like JSFiddle was calling onload on the JS input section so setting another onload function was preventing the code from running so I disabled it and made the necessary changes to make the page function.

    http://jsfiddle.net/keWD5/

    (You will need the window.onload call in your actual page.)