bobek
bobek

Reputation: 8020

jquery change() does not seem to be working

I am trying to accomplish simple calculation on few variables. I need to take the value from the

<td class="productprice"> 

and multiply it by the value from the

<input type="text" class="quantityBox" value="1"/>

And, I am using this piece of code to see if the value change to recalculate.

$(".quantityBox").change(function(){
alert("Asdasd");
});

And nothing happens. I am expecting the alert box to appear for now, so I'll just be sure that the change works.

Any ideas? Thank you.

Upvotes: 0

Views: 81

Answers (3)

Joseph Silber
Joseph Silber

Reputation: 219938

Your code works for me: http://jsfiddle.net/8RsXF/ .

If you want to do the calculation after every keypress use keyup:

$(".quantityBox").keyup(function(){
    alert("Asdasd");
});

http://jsfiddle.net/8RsXF/1/

Upvotes: 1

josh3736
josh3736

Reputation: 144912

Assuming that you've attached the handler once the DOM is ready, that should work.

Note that the change event won't fire until focus has left the textbox.

Upvotes: 2

Chandu
Chandu

Reputation: 82913

Bind the change function in document ready event.

Something like:

$(function(){
    $(".quantityBox").change(function(){ 
        alert("Asdasd"); 
    }); 
});

Note: I assume you are tabbing/moving out of the textbox to see if the change function is firing.

Upvotes: 4

Related Questions