Daku Daku
Daku Daku

Reputation: 115

Focus on ajax generated textbox

I have a "calculator" if you will. It's a shopping cart, but upon change it calculates the tax and reloads the content through ajax, registering a bit of info through php. THe problem I'm running into is that once the content is reloaded through ajax, the input textbox blurs. I want to focus onto #amt again, once the #shop reloads content. Any workarounds?

    $(document).delegate("#amt", "change", function() {
        $("#shop").load("page.php?amt="+(this).value);
    });

Upvotes: 0

Views: 401

Answers (2)

Daku Daku
Daku Daku

Reputation: 115

For whatever reason I could not get it to work with the above answers. The solution I found was to call script code from inside the loaded content (page.php)

<script>
    $("#amt").focus();
</script>

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69915

Try to set the focus inside load method success handler once the content is available. Try this.

$(document).delegate("#amt", "change", function() {
    $("#shop").load("page.php?amt="+(this).value, function(){
        $("#amt").focus(); 
    });
})

Upvotes: 2

Related Questions