最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - display message on wrong password entry - Stack Overflow

programmeradmin1浏览0评论

I have a submit button which only works when "victory" is typed into the form. Now I am trying to work on an error message to display "wrong keyword entry" if the text entered into the form field isn't "victory". here is the code

<form name="input" action="index.html" method="post" onsubmit="return check();">
<input type="text" maxlength="7" autoplete="off" name="" id="victory">

<br><input type="submit" class="bigbutton"  value="NEXT">

</form>    
<script>

function check(){
if(document.getElementById("victory").value == "victory")
    return true;
else 
   return false;

}

I have a submit button which only works when "victory" is typed into the form. Now I am trying to work on an error message to display "wrong keyword entry" if the text entered into the form field isn't "victory". here is the code

<form name="input" action="index.html" method="post" onsubmit="return check();">
<input type="text" maxlength="7" autoplete="off" name="" id="victory">

<br><input type="submit" class="bigbutton"  value="NEXT">

</form>    
<script>

function check(){
if(document.getElementById("victory").value == "victory")
    return true;
else 
   return false;

}

Share Improve this question edited Aug 1, 2014 at 10:45 user3487121 asked Aug 1, 2014 at 10:07 user3487121user3487121 531 gold badge1 silver badge11 bronze badges 2
  • When you say "work on", what exactly do you want it to do? – Craig Brett Commented Aug 1, 2014 at 10:15
  • I don't want a pop out notification. Something to appear on the page itself @CraigBrett – user3487121 Commented Aug 1, 2014 at 10:20
Add a ment  | 

2 Answers 2

Reset to default 3

If I were you I'd add an HTML element to stuff an error into. Then you can style it with CSS however you'd like.

<div id="error"></div>

Then your function would look something like this:

function check(){
    if(document.getElementById("victory").value == "victory")
        return true;
    else 
        document.getElementById("error").innerHTML = "Wrong keyword entry."
        return false;
}

You can simply add the alert in the else condition…

function check(){
   if(document.getElementById("victory").value == "victory") {
        return true;
   }
   else {    
        alert("wrong keyword entry");
        return false;
   }
 }
发布评论

评论列表(0)

  1. 暂无评论