1

I am doing a script for a little game i play and i want it to simulate enter keypress after executing this code... I researched a bit but couldn't find any thing :/ can any one help me?

if(parseInt(document.getElementById("premium_exchange_stock_wood").innerHTML)>64)
            //document.forms[0].buy_wood.value=1;
            document.forms[0].buy_wood.value=parseInt(document.getElementById("premium_exchange_stock_wood").innerHTML) ;


        else if(parseInt(document.getElementById("premium_exchange_stock_stone").innerHTML)>64)
            document.forms[0].buy_stone.value=parseInt(document.getElementById("premium_exchange_stock_stone").innerHTML) ;

        else if(parseInt(document.getElementById("premium_exchange_stock_iron").innerHTML)>64)
            document.forms[0].buy_iron.value=parseInt(document.getElementById("premium_exchange_stock_iron").innerHTML) ;
    else(window.location = "https://br86.tribalwars.com.br/game.php?village=4317&screen=market&mode=exchange");

    jQuery(":submit").click();

1 Answers1

1

Try:

Html :

<input type="text" id="test"/>

Jquery:

    var e = jQuery.Event("keypress");
e.which = 13; //choose the one you want
e.keyCode = 13;
$("#test").trigger(e);
Blesson Christy
  • 380
  • 3
  • 13
  • I think that's correct, but it doesn't seem to be working on the site I'm trying to apply the script to... I've tried adding delay but not working either. I only works if I press the enter key manually – Joao Machado Nov 17 '17 at 18:07