Jsfiddle question

I cannot get this extremely simple jsfiddle to work. It just has to warn the test when the button is pressed. What am I missing here?

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

+6
source share
4 answers

You need to change the method of loading without a wrapper (head).

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

+8
source

jQuery framework is chosen to load onDomReady , so your function is wrapped in an anonymous function jQuery $(function(){ }); and not displayed. Either modify jQuery to load as no wrap (head) or define your function in a global scope.

+2
source

See here .

You needed to define your validateForm function in a global scope in order to be able to use it in an HTML-like. Otherwise, you defined it as a function inside the onDomReady event onDomReady , which is not available outside this scope.

More "jQuery-ish" will use jQuery to handle the click event as follows:

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

See here for an example of this sentence.

+2
source

You are using jquery + ondomready. This means that any javascript you write is placed inside

 $(function() { 

and

 }); 

this leads to a problem area. Instead, you can try the following.

 window.validateForm = function() { } 
0
source

Source: https://habr.com/ru/post/893535/


All Articles