Reputation: 125
Hi I'm familiar with using onsubmit and onclick as I have used them before, but for some reason it refuses to work this time around. I've looked at my old code and tried everything to make it exactly the same yet it still will not run.
function verifypass()
{
var password = "Testpass";
var string = document.getElementByID("verifybadge");
if(string!=password) {
alert("Wrong password!");
window.location="about:blank";
}
}
<form name="receivingform" method="post">
</br></br>
<b>Please Enter Password to Verify Closure of Ticket: </b> </br>
<input type="text" size="15" maxlength="20" id="verifybadge"> </br>
<input class="button_text" type="submit" value="Delete Closed Rows" onclick="verifypass();">
</form>
Upvotes: 0
Views: 2492
Reputation: 2381
Man, it's document.getElementById
by the way, let's clean that code:
HTML:
<form name="receivingform" method="post">
<br/><br/>
<b>Please Enter Password to Verify Closure of Ticket: </b> <br/>
<input type="text" size="15" maxlength="20" id="verifybadge" /> <br/>
<input class="button_text" type="submit" value="Delete Closed Rows" onclick="verifypass()" />
</form>
Javascript:
function verifypass() {
var password = "Testpass";
var string = document.getElementById("verifybadge").value;
if(string !== password) {
alert("Wrong password!");
window.location="about:blank";
}
}
This code works
(notice the .value as suggested by @John)
Under here a snippet:
function verifypass() {
var password = "Testpass";
var string = document.getElementById("verifybadge").value;
if(string !== password) {
alert("Wrong password!");
//window.location="about:blank";
} else alert("yay");
}
<form name="receivingform" method="post">
<br/><br/>
<b>Please Enter Password to Verify Closure of Ticket: </b> <br/>
<input type="text" size="15" maxlength="20" id="verifybadge" /> <br/>
<input class="button_text" type="button" value="Delete Closed Rows" onclick="verifypass()" />
</form>
Upvotes: 3