-6

Input is "captcha_code"
https://faucet.raiblockscommunity.net/form.php
How to auto press enter?

Makyen
  • 31,849
  • 12
  • 86
  • 121
GenGit Khan
  • 1
  • 1
  • 4
  • How to auto press enter when input leng 6 char – GenGit Khan Jul 20 '17 at 08:35
  • Your question is irrelevant of Google Chrome Extensions. Not clear why you tagged google-chrome-extension. – Aefits Jul 20 '17 at 12:06
  • If you are asking about specific HTML code, then you need to include that code in the question, **not** just a link to some page. Basically, the question needs to be self-contained. Currently, if the link goes dead, then they question is too broad. – Makyen Jul 20 '17 at 21:50

3 Answers3

0

How to auto press enter when input leng 6 char sounds bit odd. If you want to trigger a "click" even when the input length is 6, here's a solution for you.

HTML:

<input type="text" placeholder="Enter the captcha" id="captcha">
<button id="submit-button">Submit Button</button>

JavaScript/Jquery:

$(document).ready(function(){
    $("#captcha").on("click",function(){
    var length = $(this).val().length;
    if(length >= 6){
        $("#submit-button").click(); //Click the submit button.
    }
    });
});
Nandan Bhat
  • 1,573
  • 2
  • 9
  • 21
0

I'd set an event handler for onkeyup and submit the form when the input length is of the required size.

Something like that:

document.getElementById('input-id').onkeyup = function(ev) {
  var el = document.getElementById('input-id');
  if (el.value.length == 6) {
    document.getElementById('form-id').submit();
  }
}

Edit: Updated to fire a Keypress event with the Enter key, as in this answer:

document.getElementById('input-id').onkeyup = function(ev) {
  var el = document.getElementById('input-id');
  if (el.value.length == 6) {
    var e = jQuery.Event("keypress");
    e.which = 13; //choose the one you want
    e.keyCode = 13;
    $("#input-id").trigger(e);

  }
}
  • i need press enter because i mere it to press enter goto tab 2,3,4,5 – GenGit Khan Jul 20 '17 at 09:52
  • You can do as https://stackoverflow.com/a/3276819/1001695 suggests, use JQuery to trigger the keypress event with the enter key code – Damián Serrano Thode Jul 20 '17 at 10:04
  • why it not working i megre it to var captcha_code = document.getElementById('captcha_code'); if (captcha_code) { captcha_code.focus(); captcha_code.addEventListener("keyup", function (e) { if (13 == e.keyCode) chrome.extension.sendMessage({ nextTab: true }); }, false); } – GenGit Khan Jul 20 '17 at 11:05
  • Here is a working example of the snippet, you can see in the developer console that the enter keypress event is logged when the text in the input field is 6 chars long https://jsfiddle.net/v67xL6qn/ – Damián Serrano Thode Jul 20 '17 at 12:18
  • i write it to extensions to work captcha site ! it not work :( can you give me js file for chrome extension – GenGit Khan Jul 21 '17 at 08:21
  • Sorry, I've never written a Chrome extension, you will have to figure it out using this code as a starting point. – Damián Serrano Thode Jul 21 '17 at 08:49
0

Assuming pressing enter and triggering submit is the same, you can use a keyup event to check the length of the input and trigger a submit when the length reaches 6:

$("#captcha").on("keyup", function() {
  if ($(this).val().length == 6) {
    console.log('Its 6 characters, we are submitting..');
    $("#submit-button").trigger('click');
  }
});

$("#submit-button").on("click", function() {
  console.log("Submitted");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" placeholder="Enter the captcha" id="captcha">
<button id="submit-button">Submit Button</button>
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35