Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 24-09-2012 07:49PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 117 ✭✭cirx08


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


  • Registered Users, Registered Users 2 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, Registered Users 2 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