Unable to find variable when calling function from onClick

I try to call a function using the onClick command, but I get the error message "Cannot find the variable" in the Safari console and no action is taken. I do not see any errors, but I must miss something that leads to failure.

Link

<a href="JavaScript:void(0);" onclick="controlWallMonitor('layout','Playback');">Show playback layout</a> 

Javascript

 <script type="text/javascript"> $(document).ready(function() { function controlWallMonitor(variable, option) { var WallMonitor = "10.0.50.163:9000"; $.ajax({ url: 'changelayout.php?target=' + WallMonitor + '&variable=' + variable + '&option=' + option, }); return false; }; }); 

I’m sure that this will become incredibly obvious, but for almost 2 hours I was looking for and trying to work something out, and couldn’t let my life consider the problem.

Greetings.

+4
source share
1 answer

Remove the call to $ (document) .ready from the function, all you have to do is put it after you include the jQuery script.

EDIT: Also, instead of using onclick, use the jQuery event handler:

HTML:

 <a href="JavaScript:void(0);" class="playback">Show playback layout</a> 

JS:

 $(document).ready(function(){ $("a.playback").click(function(){ controlWallMonitor('layout', 'Playback'); }); }); 
+8
source

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


All Articles