Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript focus() and submit() messing with eachother?

Options
  • 24-09-2012 7:49pm
    #1
    Registered Users Posts: 117 ✭✭


    I'm starting taking a look at some Javascript and I can't figure out what's wrong here. When I take out the submit() line all works fine and the textarea takes focus but as soon as I add it back in it will run everything except the focus() function?
    //ENTER SEND BUTTON
    function keyPress(e) {
        var key = e.keyCode? e.keyCode : e.charCode;
        
        if(key == 13) {
            var f = document.forms["myform"];
                f.send.disabled = true;
                f.submit();
    
            $.post('', {name: name}, function(data) {
                document.getElementById("message").value = '';
                document.getElementById("message").focus();
            });
        }
    }
    


Comments

  • Registered Users Posts: 1,082 ✭✭✭Feathers


    cirx08 wrote: »
    I'm starting taking a look at some Javascript and I can't figure out what's wrong here. When I take out the submit() line all works fine and the textarea takes focus but as soon as I add it back in it will run everything except the focus() function?
    //ENTER SEND BUTTON
    function keyPress(e) {
        var key = e.keyCode? e.keyCode : e.charCode;
        
        if(key == 13) {
            var f = document.forms["myform"];
                f.send.disabled = true;
                f.submit();
    
            $.post('', {name: name}, function(data) {
                document.getElementById("message").value = '';
                document.getElementById("message").focus();
            });
        }
    }
    

    Is that because you're sending a HTTP POST via submitting the form before the focus() method is called? What exactly is the above code doing?


  • Registered Users Posts: 117 ✭✭cirx08


    Thank for replying, noticed that a while after posting and forgot to take the thread down :P


  • Registered Users Posts: 1,082 ✭✭✭Feathers


    cirx08 wrote: »
    Thank for replying, noticed that a while after posting and forgot to take the thread down :P

    Cool, glad to hear you got it sorted ;)


  • Registered Users Posts: 117 ✭✭cirx08


    Haha spent the past two days learning Javascript, jquery and ajax and I love it that much I can't seem to get away from my computer now :L


Advertisement