javascript - Uncaught ReferenceError: MyFunction is not defined - PhoneGap -
i'm using phonegap , jquery mobile mobile web app. when try run myfunction set on onclick attribute error in console
uncaught referenceerror: myfunction not defined.
this code:
<!doctype html> <html> <head> <title>product</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="css/index.css" /> <link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css" /> <script type="text/javascript" src="cordova-2.7.0.js"></script> <script type="text/javascript" src="js/index.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="js/jquery.mobile-1.3.1.min.js"></script> <!--generation script starts here --> <script type="text/javascript"> function makeid() { var text = ""; var possible = "123456789"; for( var i=0; < 4; i++ ) text += possible.charat(math.floor(math.random() * possible.length)); return text; } function makeid1() { var text1 = ""; var possible = "123456789"; for( var i=0; < 1; i++ ) text1 += possible.charat(math.floor(math.random() * possible.length)); return text1; } function makeid2() { var text2 = ""; var possible = "abcdefghijklmnopqrstuvwxyz"; for( var i=0; < 1; i++ ) text2 += possible.charat(math.floor(math.random() * possible.length)); return text2; } function makeid3() { var text3 = ""; var possible = "123456789"; for( var i=0; < 2; i++ ) text3 += possible.charat(math.floor(math.random() * possible.length)); return text3; } function myfunction() { document.getelementbyid("demo").innerhtml="d01e-boa0-" + makeid() + "-" + makeid1() + makeid2() + makeid3(); } </script> <!-- generation script ends here --> </head> <body> <div data-role="page"> <div data-role="header" data-theme="b"> <a href="index.html" data-role="button" data-icon="home" data-iconpos="notext" data-theme="b" data-iconshadow="false" data-inline="true">home</a> <h1>product</h1> </div><!-- /header --> <div data-role="content"> <p id="demo" style="text-align:center;"></p> <input type="button" onclick="myfunction()" value="generate!" data-theme="b"> </div><!-- /content --> </div><!-- /page --> </body> </html>
i'm not sure or not, wrap code document ready, , handle click
of button jquery:
<input type="button" id="generate" value="generate!" data-theme="b">
$('#generate').on('click', function () { $("#demo").html("d01e-boa0-" + makeid() + "-" + makeid1() + makeid2() + makeid3()); });
the full code:
$(function () { function makeid() { var text = ""; var possible = "123456789"; for( var i=0; < 4; i++ ) { text += possible.charat(math.floor(math.random() * possible.length)); } return text; } function makeid1() { var text1 = ""; var possible = "123456789"; for( var i=0; < 1; i++ ) { text1 += possible.charat(math.floor(math.random() * possible.length)); } return text1; } function makeid2() { var text2 = ""; var possible = "abcdefghijklmnopqrstuvwxyz"; for( var i=0; < 1; i++ ) { text2 += possible.charat(math.floor(math.random() * possible.length)); } return text2; } function makeid3() { var text3 = ""; var possible = "123456789"; for( var i=0; < 2; i++ ) { text3 += possible.charat(math.floor(math.random() * possible.length)); } return text3; } $('#generate').on('click', function () { $("#demo").html("d01e-boa0-" + makeid() + "-" + makeid1() + makeid2() + makeid3()); }); });
check fiddle test on android.
Comments
Post a Comment