html - Javascript: Uncaught ReferenceError -
<html> <head> <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"/> <script type="text/javascript"> $(document).ready(function(){ $('#name').val('name1'); }); function clickme(){ console.log('click me called'); } </script> </head> <body> person name: <input type="text" id="name" data-bind="value:personname"> <input type="submit" value="save" onclick="javascript:clickme()"/> </body> </html>
in code above neither function inside document.ready getting executed nor "clickme" function getting executed when "save" button clicked.
when click on "save" button, uncaught referenceerror: clickme not defined error message seen.
because haven't closed script
tag of jquery
. <script>
not self-closing tag.
<script type="text/javascript" src="https://code.jquery.com/jquery- 1.11.3.js"/>
should
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script>
code:
<html> <head> <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#name').val('name1'); }); function clickme() { alert('click me called'); } </script> </head> <body> person name: <input type="text" id="name" data-bind="value:personname"> <input type="submit" value="save" onclick="javascript:clickme()" /> </body> </html>
Comments
Post a Comment