Wednesday, July 1, 2009

[jQuery] Re: Event for when a <select> is changed?

You might want to pull the variable declaration out of the anonymous function so that it can be used later (outside the function):

var str = "";
$("#theSelectsID").change(function () {
    str = $(this).val();
});

// later
alert(str);

--
Hector


On Wed, Jul 1, 2009 at 11:25 AM, James <james.gp.lee@gmail.com> wrote:

Just simplify it like:

$("#theSelectsID").change(function () {
var str = $(this).val();
//or -- var str = this.value;
});

On Jun 30, 11:51 pm, "developm...@sdinternet.co.uk"
<p...@sdinternet.co.uk> wrote:
> If you have a single dropdown list with the id of 'theSelectsID' the
> below code should store the selected item into the variable 'str'.
> Hope that helps
>
>     $("#theSelectsID").change(function () {
>           var str = "";
>           str = $("#theSelectsID").val();
>         });

No comments: