Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsfiddle question [duplicate]

I can't get this extremely simple jsfiddle to work. Its just supposed to alert test when button is clicked. What am I missing here?

http://jsfiddle.net/u9nG6/2/

like image 693
Kory Avatar asked Jul 25 '11 23:07

Kory


3 Answers

You have to change the load method to no wrap (head).

It has something to do with how the JavaScript gets loaded and when the method signature is read. http://jsfiddle.net/u9nG6/11/

like image 76
citizen conn Avatar answered Oct 24 '22 05:10

citizen conn


jQuery framework is selected to load onDomReady so your function is wrapped in the jQuery anonymous function $(function(){ }); and is not visible. Either change jQuery to load as no wrap (head) or define your function at the global scope.

like image 35
andyb Avatar answered Oct 24 '22 04:10

andyb


See here.

You needed to define your validateForm function at the global scope in order to be able to use it in the HTML like that. Otherwise you had it defined as a function within the scope of the onDomReady event, which is inaccessible outside that scope.

A more "jQuery-ish" approach would be to use jQuery to handle the click event like this:

$("#id_btnSubmit").click(validateForm);

See here for an example of that suggestion.

like image 2
Dan Tao Avatar answered Oct 24 '22 04:10

Dan Tao