Отправить форму отображается только с использованием Javascript
Я создал игру с использованием Phaser и хотел бы, чтобы мои пользователи могли заполнить свое имя в форме с одним полем для "Имя:", а затем нажать кнопку "Отправить", в которой будут указаны только что введенное имя и их высокий балл.
Вот мой код для страницы JavaScript:
Game.Leader = function(game) {
buttonContinue = null;
state = null;
};
Game.Leader.prototype = {
create: function() {
this.showLeader();
},
showLeader: function() {
this.game.add.sprite(0, 0, 'screen-leader');
this.game.add.sprite(640-213-70, 80, 'spread');
this.state = 'Leader';
this.buttonContinue = this.add.button((640-200)/2, 960-103-1, 'button-restartsmall', this.startGame, this);
this.game.add.button(640-213-10, 20, 'twitter', function() {window.open("https://www.xxxxxxxx.com/", "_blank");}, this);
this.game.add.button(640-133-10, 20, 'whatsapp', function() {window.open("https://www.xxxxxxxx.com", "_blank");}, this);
this.game.add.button(640-293-10, 20, 'face', function() {window.open("https://www.xxxxxxxx.com", "_blank");}, this);
this.game.add.button(640-194-265, 700, 'button-leader2', function() {window.open("leader.htm", "_self");}, this);
this.game.add.sprite(640-194-220, 300, 'highscore-text');
highscoreText = this.game.add.text(290, 360, "0", { font: "40px ComicBook", fill: "#FFCC00", align: "right" });
storageAPI.initUnset('highscore',0);
var highscore = storageAPI.get('highscore');
highscoreText.setText(highscore);
},
startGame: function() {
this.game.state.start('Game');
}
};
Таким образом, их высокий балл уже содержится в переменной ниже и выводится на странице выше.
var highscore = storageAPI.get('highscore');
и я хочу взять это и отправить его со своим именем в форме, добавив что-то в сценарий выше - но что?
при отправке формы необходимо выполнить следующую функцию, чтобы опубликовать ее в службе списка лидеров app42 - см. мои два // комментария:
function saveScore(n){
if(n){
var gameName = "xxxxx";
var userName = name; //this is where the name would go from the form
if(userName == ""){
userName = "Guest";
}
var gameScore = x; //what needs to go here to grab the highscore text already available?
var result;
var scoreBoardService = new App42ScoreBoard()
scoreBoardService.saveUserScore(gameName,userName,gameScore,{ success: function(object){} });
}
}
Итак вопросы:
- Что мне нужно, чтобы добавить первый скрипт, который будет добавлять форму исключительно в JavaScript?
- Что мне нужно изменить, когда мои два // комментария находятся во втором скрипте, чтобы они могли публиковать данные?
Большое спасибо за любую помощь!