0

I inherited some javascript code. One of them is a function chg(x) which reloads the page after a drop down list's value has been changed.

How do I use jquery to change the drop down list's value and call chg(x) when the value is changed ?

caitriona
9,2414 gold badges34 silver badges36 bronze badges
asked Jul 29, 2010 at 16:16
1
  • At the end of the day all jQuery is doing is defining a bunch of functions in JavaScript. It's not like it's a separate language, it's just a library. Commented Oct 4, 2012 at 14:44

2 Answers 2

1

Use the .change method:

$('#myDropdownID').change(function() {
 $(this).val('some value'); //will change the dropdown's selected value to whatever you want
 chg(x);
});

Assuming that the chg() function is somewhere in the code.

More references here: .change() jquery method

answered Jul 29, 2010 at 16:20
Sign up to request clarification or add additional context in comments.

Comments

1

You should be able to call chg anywhere where it's valid to call a function, since jQuery IS Javascript.

If chg() doesn't work, then provide us with some code specific to your situation, because it may not be defined in global context or scope such to call it like that.

answered Jul 29, 2010 at 16:20

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.