I am reading a value from HTML adding 1 to that that number and then updating the number within the HTML. When I do this, it returns the number back into the HTML as NaN.
I've tried using parseInt() and Number() but I still get the same output.
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div class="inputForm">
<form id="frm1" onsubmit="return formSubmit()">
<h3>Update League Table!</h3>
<section class="playerOne">
<label for="playerOne">Player One Name:</label>
<select name="playerOne" id="playerOne">
<option value="name1">name1</option>
<option value="name2">name2</option>
<option value="name3">name3</option>
<option value="name4">name4</option>
</select>
</section>
<br>
<section class="playerTwo">
<label class="playerTwoText" for="playerTwo">Player Two Name:</label>
<select name="playerTwo" id="playerTwo">
<option value="name1">name1</option>
<option value="name2">name2</option>
<option value="name3">name3</option>
<option value="name4">name4</option>
</select>
<br>
</section>
<br>
<section class="winner">
<span>Please select winner:</span>
<br>
<input id="userOne" type="radio" name="winnerWinner" value="userOne">
<label for="userOne">Player One</label>
<input id="userTwo" type="radio" name="winnerWinner" value="userTwo">
<label for="userTwo">Player Two</label>
</section>
<br>
<section class="submission">
<input type="submit" value="Submit">
</section>
<p id="submitComplete">testing</p>
<p id="name1GP">0</p><p id="name1Wins">0</p>
</form>
</div>
</body>
</html>
JAVASCRIPT
function formSubmit() {
var p1 = document.getElementById("playerOne").value;
var p2 = document.getElementById("playerTwo").value;
var radiobox = document.querySelector('input[name="winnerWinner"]:checked').value;
if (p1 === "name1" && radiobox === "userOne") {
var name1GP = document.getElementById("name1GP").value;
name1GP += 1
document.getElementById("name1GP").innerHTML = name1GP
}
return false;
}
The value I am reading is id="name1GP" I want to add 1 to this value and then return it to the HTML, however instead of returning 1 it returns NaN.