I have 2 main functions which are near enough exactly the same except variable names and the table it is using.
I am using phonegap, html, javascript, JQuery Mobile.
function eventSoccer is being reached as the first alert is appearing, however the data input is not being stored and instead the page just refreshes.
function registerUser works perfectly fine, to which the sql query is displayed and the alert 'user has been registered' appears and the data is in the database.
Can anyone identify why function eventSoccer doesn't seem be working? As the two functions are nearly immaculate.
eventSoccer -
function eventSoccer() {
alert("eventSoccer hit");
var TitleT = document.getElementById("txttitle").value;
var LocationL = document.getElementById("txtlocation").value;
var PeopleP = document.getElementById("txtpeople").value;
var DateD = document.getElementById("txtdate").value;
var DescriptionD = document.getElementById("txtdesc").value;
db = window.openDatabase("SoccerEarth", "2.0", "SoccerEarthDB", 2 * 1024 * 1024);
db.transaction(function(tx) {
NewSoccer(tx, TitleT, LocationL, PeopleP, DateD, DescriptionD);
}, errorEvent, successEvent);
}
function NewSoccer(tx, TitleT, LocationL, PeopleP, DateD, DescriptionD) {
var _Query = ("INSERT INTO SoccerEvents(Title, Location, NoPeople, Date, Description) values ('" + TitleT + "','" + LocationL + "','" + PeopleP + "','" + DateD + "', '" + DescriptionD + "')");
alert(_Query);
tx.executeSql(_Query);
}
function errorEvent(error) {
navigator.notification.alert(error, null, "Event not created", "cool");
}
function successEvent() {
navigator.notification.alert("The event has now been created", null, "Information", "ok");
}
registerUser -
function registerUser() {
var Username = document.getElementById("txtusername").value;
var Firstname = document.getElementById("txtfirstname").value;
var Lastname = document.getElementById("txtlastname").value;
var Email = document.getElementById("txtemail").value;
var Password = document.getElementById("txtpassword").value;
var Confirmpass = document.getElementById("passwordconfirm").value;
db = window.openDatabase("SoccerEarth", "2.0", "SoccerEarthDB", 2 * 1024 * 1024);
db.transaction(function(tx) {
NewUser(tx, Username, Firstname, Lastname, Email, Password, Confirmpass);
}, errorRegistration, successRegistration);
}
function NewUser(tx, Username, Firstname, Lastname, Email, Password, Confirmpass) {
var _Query = ("INSERT INTO SoccerEarth(UserName, FirstName, LastName, Email, Password, CPass) values ('" + Username + "','" + Firstname + "','" + Lastname + "','" + Email + "', '" + Password + "', '" + Confirmpass + "')");
alert(_Query);
tx.executeSql(_Query);
}
function errorRegistration(error) {
navigator.notification.alert(error, null, "Got an error mate", "cool");
}
function successRegistration() {
navigator.notification.alert("User data has been registered", null, "Information", "ok");
}
HTML -
<div data-role="content">
<br>
<form>
<label for="txttitle">Title</label>
<input type="text" id="txttitle">
<br>
<label for="txtlocation">Location</label>
<input type="text" id="txtlocation">
<br>
<label for="txtpeople">Number Of People</label>
<input type="text" id="txtpeople">
<br>
<label for="txtdate">Date</label>
<input type="text" id="txtdate">
<br>
<label for="textdesc">Description</label>
<textarea name="textarea" id="textdesc"></textarea>
<br>
<input type="submit" value="submit" onclick="return eventSoccer()">
</form>
</div>