0

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>

1 Answer 1

3

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>

Sign up to request clarification or add additional context in comments.

8 Comments

Guess its going to be one of those days. Happy Monday everyone
@AggieEngr, You could've simply debugged this in the console.
As it was displayed, I am pretty new to this @Mouser. Thanks for the heads up though, I'll use the console from now on
Hey now even if I submit the right password, the alert is still popping up saying its the wrong password. Any ideas?
try modifying != to !== so it results: if(string !== password)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.