0

My form calculations work in my jsfiddle, however in my wordpress page, it says Uncaught TypeError: Cannot set property 'onchange' of null. Is my page not loading the function when it loads?

(javascript in the header)

function doTotal(form) {
    var a = (+form.halfday1.value);
    var b = (+form.fullday1.value);


    form.total1.value = a + b ;
}
document.getElementById("quote").onchange = function (){doTotal(this)};

http://jsfiddle.net/2666c/

user1426583
  • 309
  • 2
  • 8
  • 25

1 Answers1

1

Your code not run, becouse on moment it try to find the <element id="quote"/> there are no such elements. You need to put your code under this element. Or run it on document load event. As example:

jQuery(document).ready(function($){
    jQuery('#quote').change(function (){doTotal(this)});
});
Community
  • 1
  • 1
Arthur Halma
  • 3,903
  • 3
  • 20
  • 42