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
2 Answers
Reset to default 3If 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;
}
}