I'm using a function I found here in another thread to prevent my form from submitting which works on my laptop, however, when I pushed my current changes to my gh_pages branch to test it on my phone I noticed the form is still trying to submit. I'm currently doing it this way because I'm not sending the form data to a backend yet, but I still would like to utilize the functionality of the 'required' attribute in the input fields. Thanks for any help in advance. Here is the related code from my .js and .html files:
js
document.getElementById('gameData').onsubmit = function() {
game['game'] = {};
game.game['id'] = generateId(20);
game.game['courseName'] = document.getElementById('course').value;
game.game['gameLength'] = courseLength;
game.game['players'] = {};
var participants = document.querySelectorAll('.currentPlayers');
participants.forEach(function(name){
game.game.players[generateId(5)] = name.value;
})
generateCard(game.game.gameLength)
// prevent form submission
return false;
}
Form
<form id="gameData">
<h3>What course are you playing?</h3>
<input type="text" maxlength="40" id="course" required>
<h3>How many holes are you playing?</h3>
<div class="gameLength noHiLte">
<input type="radio" name="gameLength" value="9" id="nine" checked/>
<label class="nine radio" for="nine">9</label>
<span>or</span>
<input type="radio" name="gameLength" value="18" id="eighteen"/>
<label class="radio" for="eighteen">18</label>
</div>
<div class="addPlayers">
<h3>Add up to four players:</h3><i class="fa fa-plus noHiLte" aria-hidden="true"></i>
<!-- New player Input fields generated here -->
</div>
<input type='submit' class="startGame hide" value='Tee Off!'>
disable=true
work for you?event.preventDefault