how to link js file to php file - javascript

I'm trying to send my form data of php file to js file but I can't sure that php file is called by js file.
<!DOCTYPE html>
<html class="hide-sidebar ls-bottom-footer" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Learning</title>
<link href="css/vendor.min.css" rel="stylesheet">
<script type ="text/javascript" src="api/serve.js"></script>
<link href="css/theme-core.min.css" rel="stylesheet">
<link href="css/module-essentials.min.css" rel="stylesheet" />
<link href="css/module-material.min.css" rel="stylesheet" />
<link href="css/module-layout.min.css" rel="stylesheet" />
<link href="css/module-sidebar.min.css" rel="stylesheet" />
<link href="css/module-sidebar-skins.min.css" rel="stylesheet" />
<link href="css/module-navbar.min.css" rel="stylesheet" />
<link href="css/module-messages.min.css" rel="stylesheet" />
<link href="css/module-carousel-slick.min.css" rel="stylesheet" />
<link href="css/module-charts.min.css" rel="stylesheet" />
<link href="css/module-maps.min.css" rel="stylesheet" />
<link href="css/module-colors-alerts.min.css" rel="stylesheet" />
<link href="css/module-colors-background.min.css" rel="stylesheet" />
<link href="css/module-colors-buttons.min.css" rel="stylesheet" />
<link href="css/module-colors-text.min.css" rel="stylesheet" />
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"> </script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>
<body class="login">
<div id="content">
<div class="container-fluid">
<div class="lock-container">
<div class="panel panel-default text-center paper-shadow" data-z="0.5">
<h1 class="text-display-1">Create account</h1>
<div class="panel-body">
<!-- Signup -->
<form id="signup" action="" method="POST">
<div class="form-group">
<div class="form-control-material">
<input id="firstName" type="text" class="form-control" name="firstname" value="">
<label for="firstName">First name</label>
</div>
</div>
<div class="form-group">
<div class="form-control-material">
<input id="lastName" type="text" class="form-control" name="lastName" value="">
<label for="lastName">Last name</label>
</div>
</div>
<div class="form-group">
<div class="form-control-material">
<input id="email" type="email" class="form-control" name="email" value="">
<label for="email">Email address</label>
</div>
</div>
<div class="form-group">
<div class="form-control-material">
<input id="password" type="password" class="form-control" name="password" value="">
<label for="password">Password</label>
</div>
</div>
<div class="form-group">
<div class="form-control-material">
<input id="passwordConfirmation" type="password" class="form-control" placeholder="Password Confirmation">
<label for="passwordConfirmation">Re-type password</label>
</div>
</div>
<div class="form-group text-center">
<div class="checkbox">
<input type="checkbox" id="agree" />
<label for="agree">* I Agree with Terms & Conditions!</label>
</div>
</div>
<div class="text-center">
<button id="submit" class="btn btn-primary" type="submit" >Create an Account</button>
</div>
</form>
<!-- //Signup -->
</div>
</div>
</div>
</div>
</div>
<script>
var colors = {
"danger-color": "#e74c3c",
"success-color": "#81b53e",
"warning-color": "#f0ad4e",
"inverse-color": "#2c3e50",
"info-color": "#2d7cb5",
"default-color": "#6e7882",
"default-light-color": "#cfd9db",
"purple-color": "#9D8AC7",
"mustard-color": "#d4d171",
"lightred-color": "#e15258",
"body-bg": "#f6f6f6"
};
var config = {
theme: "html",
skins: {
"default": {
"primary-color": "#42a5f5"
}
}
};
</script>
<!-- Separate Vendor Script Bundles -->
<script src="js/vendor-core.min.js"></script>
<script src="js/vendor-countdown.min.js"></script>
<script src="js/vendor-tables.min.js"></script>
<script src="js/vendor-forms.min.js"></script>
<script src="js/vendor-carousel-slick.min.js"></script>
<script src="js/vendor-player.min.js"></script>
<script src="js/vendor-charts-flot.min.js"></script>
<script src="js/vendor-nestable.min.js"></script>
<script src="js/module-essentials.min.js"></script>
<script src="js/module-material.min.js"></script>
<script src="js/module-layout.min.js"></script>
<script src="js/module-sidebar.min.js"></script>
<script src="js/module-carousel-slick.min.js"></script>
<script src="js/module-player.min.js"></script>
<script src="js/module-messages.min.js"></script>
<script src="js/module-maps-google.min.js"></script>
<script src="js/module-charts-flot.min.js"></script>
<script src="js/theme-core.min.js"></script>
</body>
</html>\
And my js file is as follws.
serve.js
$(document).ready(function(){
$("form").click( function(e){
e.preventDefault();
// get values from textboxs
var name = $('#firstName').val();
var lname = $('#lastName').val();
var mail = $('#email').val();
var password = $('#password').val();
var confpass = $('#passwordConfirmation');
$.ajax({
url: "api/learnapi.php",
type: "post",
dataType: "json",
data: {type: "signup", Name: name, Lname: lname, Pass: password, Email: mail,Pass1:confpass },
//type: should be same in server code, otherwise code will not run
ContentType: "application/json",
success: function (response) {
alert(JSON.stringify(response));
},
error: function (err) {
alert(JSON.stringify(err));
}
});
});
});
I'm not sure that these my two files are linked together.
How do is link them

In your server.js file replace $('form') with $('form #submit')
Right now you are calling click event on the form instead of button.
Check view source to see if your file is actually included in dom.

Related

How to implement a form with a searcheable map in Leaflet

I am new in the development of this map web application, and I want to implement a form with a map which can get the longitude and latitude through the search bar and put it in the database. I am using the Leaflet-Search plugin. I tried following the instructions, but I still can't understand how to implement it properly.
For reference, here is the form picture and code:
Picture: Form picture
Code:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HelpThePoor</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght#400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href={{url('css/main.css')}}>
<link rel="stylesheet" href="https://unpkg.com/leaflet#1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet#1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<script src="https://unpkg.com/leaflet-geosearch#3.0.0/dist/geosearch.umd.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/leaflet-geosearch#3.0.0/dist/geosearch.css"/>
<!-- Styles -->
<style>
body {
font-family: 'Nunito', sans-serif;
}
</style>
</head>
<body>
Kembali
<br>
<div class="container">
<form action="/createdonor" method = "post">
#csrf
<div class="form-row">
<div class="col">
<label>Nama:</label> <!--for getting the name-->
<input type="text" class="form-control" name="name" placeholder="Nama">
</div>
<div class="col"> <!--for getting the details of help-->
<label>Bantuan apa yang anda tawarkan?:</label>
<input type="text" class="form-control" name="help_offered" placeholder="Ceritakan secara lanjut bantuan anda">
</div>
<div class="col">
<label>Nombor Telefon:</label> <!--for getting the phone number-->
<input type="text" class="form-control" name="tel_number" placeholder="No. telefon anda">
</div>
<div class="col">
<div id="formmap"> <!--the supposedly searcheable map-->
</div>
</div>
<div class="col">
<label>Jenis bantuan:</label> <!--help type-->
<input type="text" class="form-control" name="help_type" placeholder="Sila pilih jenis bantuan anda">
</div>
<div class="col">
<label>Maklumat tambahan:</label> <!--additional details-->
<input type="text" class="form-control" name="add_info" placeholder="Maklumat tambahan">
</div>
</div>
<br>
<button type="submit" class="btn btn-success">Daftar Bantuan Saya!</button>
</form>
</div>
<script> <!--the JS for the searcheable map-->
const formmap = L.map('formmap').setView([1.465036, 830.428012], 13);
L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(formmap);
const search = new GeoSearch.GeoSearchControl({
//provider: new GeoSearch.OpenStreetMapProvider(),
});
formmap.addControl(search);
function searchEventHandler(result) {
console.log(result.location);
}
formmap.on('geosearch/showlocation', searchEventHandler);
</script>
</body>
</html>
And here's the database: Database picture
I am new in this type of web application, and I quite slow on getting the basics of JS currently.

Inserted value disappeares after pressing submit

I want to create a form in HTML that can take the inserted Name by the user and then after pressing submit shows the corresponded value (Age) to that user. This is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="MyMain.css">
<script language="JavaScript">
function myFunction() {
document.getElementById('myshow').innerHTML =
document.getElementById("Name").value;
}
</script>
</head>
<body>
<div class="container">
<div>
<fieldset>
<form action="">
<div class="row">
<div form-group">
<label for="fname">Your Name: </label>
<input type="text" class="form-control" name="name" id="Name" placeholder="Jon" value="">
</div>
</div>
<div>
<input type="submit" class="button" onclick="myFunction();" value="Submit"<br/>
</div>
</div>
</form>
</fieldset>
</div>
</div>
<div class="container">
<fieldset>
<div>
<label>Age: </label>
<p><span id='myshow'></span></p>
</div>
</fieldset>
</div>
</body>
</html>
The problem is that after pressing submit the Name will be shown in the myshow span section(Age:) just
for a fraction of second and then it disappeares and url changes to localhost:5000/?Name=Jack rather than localhost:5000/the current path/?Name=Jack
You should use onSubmit on the form element to call the function and then return false.
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="MyMain.css">
<script language="JavaScript">
function myFunction() {
document.getElementById('myshow').innerHTML =
document.getElementById("Name").value;
return false;
}
</script>
</head>
<body>
<div class="container">
<div>
<fieldset>
<form action="" onSubmit="return myFunction();">
<div class="row">
<div form-group">
<label for="fname">Your Name: </label>
<input type="text" class="form-control" name="name" id="Name" placeholder="Jon" value="">
</div>
</div>
<div>
<input type="submit" class="button" value="Submit"><br/>
</div>
</div>
</form>
</fieldset>
</div>
</div>
<div class="container">
<fieldset>
<div>
<label>Age: </label>
<p><span id='myshow'></span></p>
</div>
</fieldset>
</div>
</body>
</html>
Ps: you did not close the submit tag properly
I think that you don't need submit.
If you don't need to submit, You have to change this code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="MyMain.css">
<script language="JavaScript">
function myFunction() {
document.getElementById('myshow').innerHTML =
document.getElementById("Name").value;
}
</script>
</head>
<body>
<div class="container">
<div>
<fieldset>
<div class="row">
<div form-group">
<label for="fname">Your Name: </label>
<input type="text" class="form-control" name="name" id="Name" placeholder="Jon" value="">
</div>
</div>
<div>
<input type="button" class="button" onclick="myFunction();" value="Submit"<br/>
</div>
</div>
</fieldset>
</div>
</div>
<div class="container">
<fieldset>
<div>
<label>Age: </label>
<p><span id='myshow'></span></p>
</div>
</fieldset>
</div>
</body>
</html>

How do i stop redirection on clicking Login button when user-name & password empty?

Javascript Jquery Experts,
I need a little help here.
This is my code, when i click on login button without putting any value in user-name & password it show message "All fields are required" but instantly as showen this message it dissapear and display unexpected message like you see when click on login button.
Now what i want ? i want when it display "All fields are required" then this message should be stable not redirect to the other unexpected message.
check also in jsfiddle: https://jsfiddle.net/m1aaaqo9/14/
1: when you click on login button checking in jsfiddle it redirect to this message: {"error":"key missing: title"}
2: I also put the same coding in my page: https://testjsvascripts.blogspot.com/p/javascript-test.html
Now when you click on login on my given page, it will redirect to display this message "Method not allowed error 405" and also add # after .html in url which i dont want.
3: same when you click on run snippet here and click on login without putting any value in user-name & password fields it will show this message "The custom error module does not recognize this error."
So my question is that: i want to display only this message " All fields are required " thats is..there should be no further redirections....So how to fix it in my code. ?
jQuery(document).ready(function($){
$("#submit").click(function(){
var name= $("#name").val();
var pass = $("#pass").val();
if(name == '' || pass == ''){
$("#Required").html("All Fields Are Required").css("color","red");
}else if(name == "admin" && pass == "123"){
$("#form").html('<h4>User Login Successfully</h4>Back').css('color','green');
}else{
$("#error").html("User Are Not Valid");
}
});
});
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Validation Form</title>
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>Login Form</h1>
<span>Name:admin</span>
<span>password:123</span>
<div class="row">
<div class="col-md-4">
<form action="#" method="post" class="form-box" id="form">
<div class="form-group">
<label>Name:</label>
<input type="text" id="name" name="name" class="form-control" placeholder="Enter Name"/>
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" id="pass" name="pass" class="form-control" placeholder="Enter Password"/>
</div>
<div class="form-group">
<input type="submit" id="submit" name="pass" class="btn btn-md btn-info" value="Login"/>
<span id="Required" style="color:#ff0000;"></span>
</div>
<span id="error" style="color:#ff0000"></span>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
</body>
</html>
jQuery(document).ready(function($){
$("#submit").click(function(){
var name= $("#name").val();
var pass = $("#pass").val();
if(name == '' || pass == ''){
$("#Required").html("All Fields Are Required").css("color","red");
}else if(name == "admin" && pass == "123"){
$("#form").html('<h4>User Login Successfully</h4>Back').css('color','green');
}else{
$("#error").html("User Are Not Valid");
}
return false;
});
});
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Validation Form</title>
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>Login Form</h1>
<span>Name:admin</span>
<span>password:123</span>
<div class="row">
<div class="col-md-4">
<form action="#" method="post" class="form-box" id="form">
<div class="form-group">
<label>Name:</label>
<input type="text" id="name" name="name" class="form-control" placeholder="Enter Name"/>
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" id="pass" name="pass" class="form-control" placeholder="Enter Password"/>
</div>
<div class="form-group">
<input type="submit" id="submit" name="pass" class="btn btn-md btn-info" value="Login"/>
<span id="Required" style="color:#ff0000;"></span>
</div>
<span id="error" style="color:#ff0000"></span>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
</body>
</html>
jQuery(document).ready(function($){
$("#submit").click(function(){
var name= $("#name").val();
var pass = $("#pass").val();
if(name == '' || pass == ''){
$("#Required").html("All Fields Are Required").css("color","red");
}else if(name == "admin" && pass == "123"){
$("#form").html('<h4>User Login Successfully</h4>Back').css('color','green');
}else{
$("#error").html("User Are Not Valid");
}
});
});
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Validation Form</title>
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>Login Form</h1>
<span>Name:admin</span>
<span>password:123</span>
<div class="row">
<div class="col-md-4">
<form action="#" method="post" class="form-box" id="form">
<div class="form-group">
<label>Name:</label>
<input type="text" id="name" name="name" class="form-control" placeholder="Enter Name"/>
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" id="pass" name="pass" class="form-control" placeholder="Enter Password"/>
</div>
<div class="form-group">
<input type="button" id="submit" name="pass" class="btn btn-md btn-info" value="Login"/>
<span id="Required" style="color:#ff0000;"></span>
</div>
<span id="error" style="color:#ff0000"></span>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
</body>
</html>

jQuery AJAX call not succeeding/running

I'm using Rapid API to save my users emails and passwords. My send function is being called onclick, but I don't think the program is running through the AJAX call.
I'm not sure what to do. Please help.
signup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ShapeBootstrap Clean Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="img/favicon.png">
<!-- SCRIPT
============================================================-->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.js"></script>
<script src = "script.js"></script>
</head>
<body>
...
<div class="container">
<div class="form-wrap">
<div class="tabs">
<h3 class="signup-tab"><a class="active" href="#signup-tab-content">Sign Up</a></h3>
<h3 class="login-tab">Sign In</h3>
</div><!--.tabs-->
<div class="tabs-content">
<div id="signup-tab-content" class="active">
<form class="signup-form">
<input type="email" class="input" id="user_email" autocomplete="on" placeholder="Email">
<input type="password" class="input" id="user_password" autocomplete="on" placeholder="Password">
<button onclick="send()" class="button">Sign Up</button>
</form><!--.login-form-->
<div class="help-text">
<p>By signing up, you agree to our</p>
<p>Terms of service</p>
</div><!--.help-text-->
</div><!--.signup-tab-content-->
<div id="login-tab-content">
<form class="login-form" action="" method="post">
<input type="text" class="input" id="user_login_email" autocomplete="off" placeholder="Email">
<input type="password" class="input" id="user_pass" autocomplete="off" placeholder="Password">
<input type="password" class="input" id="user_topic" autocomplete="off" placeholder="Your course choice">
<input type="submit" class="button" value="Login">
</form><!--.login-form-->
</div><!--.login-tab-content-->
</div><!--.tabs-content-->
</div><!--.form-wrap-->
</div>
<!--Footer
==========================-->
<footer>
<div class="container">
<div class="row">
<div class="span6">Copyright &copy 2013 Shapebootstrap | All Rights Reserved <br>
<small>Aliquam tincidunt mauris eu risus.</small>
</div>
<div class="span6">
<div class="social pull-right">
<img src="img/social/googleplus.png" alt="">
<img src="img/social/dribbble.png" alt="">
<img src="img/social/twitter.png" alt="">
<img src="img/social/dribbble.png" alt="">
<img src="img/social/rss.png" alt="">
</div>
</div>
</div>
</div>
</footer>
<!--/.Footer-->
<script>
jQuery(document).ready(function($) {
tab = $('.tabs h3 a');
tab.on('click', function(event) {
event.preventDefault();
tab.removeClass('active');
$(this).addClass('active');
tab_content = $(this).attr('href');
$('div[id$="tab-content"]').removeClass('active');
$(tab_content).addClass('active');
});
});
</script>
</body>
</html>
script.js
var emailInput;
var passwordInput;
function send() {
emailInput = document.getElementById("user_email").value;
passwordInput = document.getElementById("user_password").valu
e;
jQuery.ajax({
url: "",
type: "POST",
contentType: "application/x-www-form-urlencoded",
data: {
"email": emailInput,
"password": passwordInput,
},
})
.done(function(data, textStatus, jqXHR) {
console.log("HTTP Request Succeeded: " + jqXHR.status);
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log("HTTP Request Failed");
})
.always(function() {
/* ... */
});
}
Use these changes:
1)Place your jquery.js script above bootstrap.min.js
2) Specify type attribute to button. Sign Up.This is coz different browsers interpret the button type differently when no type attribute is specified
3) Remove content-type in $.ajax. This is coz, by default jquery sends the request as 'application/x-www-form-urlencoded'
4) Remove double quotes of data values - eg. data: { email: emailInput, password: passwordInput, };

"pageinit" event not firing

I have tried to get this work for hours.
Both test pageinit and pageshow on row 1 in login.js with no response at all, but the page is still being loaded and I not getting any javascript error when I run it in FF.
From index.html
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PSForum Notiser</title>
<link rel="stylesheet" href="js/jquery.mobile/jquery.mobile-1.3.2.min.css" />
<script type="text/javascript" src="phonegap.js"></script>
<script src="js/jquery.mobile/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mobile/jquery.mobile-1.3.2.min.js"></script>
<script src="js/main.js"></script>
<script src="js/login.js"></script>
</head>
From login.html
<div id="loginPage" data-role="page">
<div data-role="content">
<form id="loginForm">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" placeholder="Username" />
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="" placeholder="Password" />
</div>
<input type="submit" value="Login" id="submitButton">
</form>
</div>
</div>
From login.js (the part wish not running)
$("#loginPage").on('pageinit', function(){
alert("Hello world!");
console.log("loginPage is loaded");
checkPreAuth();
var form = $("#loginForm");
$(form).on("submit",handleLogin);
if(window.localStorage["username"] != undefined) {
$("#username", form).val(window.localStorage["username"]);
}
});
I hope the wisdom of stackoverflow can help me find why $("#loginPage").on('pageinit') not firing?
Best regards

Categories

Resources