1

I used to have a text input at #element_3, where you may type in a number, and a function is run on that number, and the results are outputted dynamically to parts of the page.

I've changed that text input into a dropdown menu, but I don't know what to change in my JS code so that it works. I hope I've explained enough.

Here's my code - http://slexy.org/view/s2cwHc5do2

Bold It seems my problem lies in this line:

$('#element_3').bind('keydown keyup keypress', calcPrice);

It would run the function when something was typed in, hence the keydown keyup keypress. But how do I make it work if there is no typing, but just a select element?

asked Jan 26, 2011 at 17:59
2
  • 1
    In the future, please don't refer to a select element as a "dropdown menu". They are not the same, as a dropdown menu usually refers to a CSS menu with hover effects. Commented Jan 26, 2011 at 18:02
  • 1
    $('#element_3').bind('change', calcPrice); Commented Jan 26, 2011 at 18:11

3 Answers 3

1
$("#element_3").change(function() { whetever you want in the function });

check out the jquery docs on change, they use the .change() function when a select has a value changed

http://api.jquery.com/change/

answered Jan 26, 2011 at 18:14
Sign up to request clarification or add additional context in comments.

Comments

1

try this $('#element_3').bind('change', calcPrice);

although hard to say if your calcPrice function has been re-factored to handle selection rather than input

answered Jan 26, 2011 at 18:14

Comments

0

@Andrei Korchagin: Working example -- http://jsfiddle.net/Mvwuq/

Just add change to your bind:

$('#element_3').bind('change keydown keyup keypress', calcPrice);
answered Jan 26, 2011 at 18:14

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.