user3775122
user3775122

Reputation: 1

Trigger event when i hit enter button in textbox

I have following code

$("body").on("click", "#pp_full_res button[name^=calc_shipping]", function () {})

Which works perfectly when I click on button.

I have another textbox which has id myid. I want trigger above same function when someone hit enter button in textbox.

How can i achieve this?

Upvotes: 0

Views: 75

Answers (1)

webkit
webkit

Reputation: 3369

like so:

$("body").on("click", "#pp_full_res button[name^=calc_shipping]", myWorkingFunction);
$("textarea#myid").on('keyup', checkEnter);


function checkEnter(e) {
    if (e.keyCode==13) {
        e.preventDefault();
        myWorkingFunction();
    }
}

Notice: move your working function to an external function so you can call it from different places..

Upvotes: 2

Related Questions