Doubtful this needs much explaining but I think I need a second set of eyes to check this out because I just cannot fathom why it won’t! Try using the “Energy Calculator” and no value will be returned when submitted despite me approaching it in the same way as the “Battery Charge Calculator” which does work.
Share
To elaborate on @alex’s answer, you have selected the
onLoadoption of jsFiddle, which places your JavaScript code inside of an anonymous function:Try this on for size: http://jsfiddle.net/mattball/Cbsa8/. All I did was select
no wrap (head)andNo library.Keep in mind that it’s better coding practice to write unobtrusive JavaScript. In this case you’d bind the event handler with JavaScript, using
attachEvent(for IE <9) oraddEventListener(for real browsers).Edit re: OP edits
Open a console and the problem is immediately obvious after trying to use the Energy Calculator:
which is this line:
You’re accessing the wrong form. You need to change all cases of
forms['0']toforms[1]in the energy calculator’s code. Note the omitted quotes, by the way –document.formsis an array, not an object!Also, you’re clearly using jQuery, but you’re not using it everywhere you could. Why not? There’s a lot of room for improvement in your code. It’s cleanup time!
HTML
JavaScript
Demo: http://jsfiddle.net/mattball/JSpaU/