How can you autosubmit in JQuery with a specific keyword?

Viewed 41

I've tryed to make a script for a kind of autosubmit that opens a new tab when you put in a specific keyword, yet its not seeming to work. Is there anyway to do this with another JS event?

  var text = $("#mytext");
var form = $("#myform");
text.bind("change keyup", function() {
    if( $(this).val() == "keyword" )
    $("#myform").openLinkInNewWindow('https://wikipedia.org/');
});
form id="myform" action="" method="post">
  <input type="text" id="mytext" name="mytext" value="" placeholder="type here!" />
</form>
2 Answers

what are you trying to do? openLinkInNewWindow is not a function. if you want to submit the form then you can do something like this:

var text = $("#mytext");
var form = $("#myform");
text.bind("change keyup", function() {
    if( $(this).val() == "keyword" )
    $("#myform").submit();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="myform" action="" method="post">
  <input type="text" id="mytext" name="mytext" value="" placeholder="type here!" />
</form>

you can simple check if is equal then use window.open to open new tab.

var text = $("#mytext");
text.bind("change keyup", function() {
    if( $(this).val() == "wikipedia" )
    window.open('https://it.wikipedia.org/', '_blank');
    
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="myform" action="" method="post">
  <input type="text" id="mytext" name="mytext" value="" placeholder="type here!" />
</form>

here don't work, use this fiddle for test

Related