Frage

I've got a form, where i put information in with greasemonkey. The form got no ID or Class...

When you manauly put something in the inputbox, and press enter, it get's submitted and you're off... I want to achief the same with jquery.

Changing the value's of the input boc is not the problem, but submitting.

Ive got the following code;

e = jQuery.Event("keypress");
    e.which = 13;
    e.keyCode = 13;
    $("#inputy").focus();
    $("#inputy").trigger(e);

But this doesn't work... So how does i simulate an enter in the inputbox with the ID inputy?

Greetz TWCrap

War es hilfreich?

Lösung

So you want to submit the form? You can try:

$("#inputy").keyup( function( event )
{
    if(event.keyCode == 13)
    {
        var form = $( "#inputy" ).closest( "form" );
        form.submit( );
    }
});

On every key-up we check for the Enter key. If the Enter key was released we then find the closest form and submit it.

Andere Tipps

Probably pressing enter on <input> fire submit() method on entire <form> so try do it after you fill up your <input> using following method: $("form").submit().

Anyway, is there jquery for sure on that site? Are there any errors on console?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top