I'm protecting my html form using javascript because my users can just change the input values and I want to check if the input value is equal to the random generated number. I'm using an if/else statement and the if else statement isn't working.
var pokeid = '+res.id+'; //generates random id
var html = '';
html += '<form id="myForm" action="myurl.net" method="post">';
html += ' <input type="hidden" id="goid" name="goid" value="'+res.id+'" >';
html += ' <input type="hidden" name="level" value="'+res.level+'" />';
html += ' <input value="Battle!" class="button" onclick="myFunction()" />';
</script>
<script type= "text/javascript">
function myFunction()
{
if (pokeid != document.getElementById("goid").value; ) {
window.location = '("http://www.myurl.net/index.php")';
}else{
document.getElementById("myForm").submit();
}
}
</script>
pokeid = 12345in their console, right?