You'd have to set a variable with a scope that both functions can
access. For your case, you probably just set a global variable.

'var' sets a variable.

var my_val = '';

$('select').change(function() {

        $('select option:selected').each(function() {
                my_val = $(this).val();  // remove the 'var' here
        });//end each

});//end change

$('#my_submit').submit(function() {

        var action = $('form').attr('action');
        // How do I get my_val variable into here??
        $('form').attr('action', action + 'new_parm=' + my_val);

On Aug 12, 2:04 pm, Nic Hubbard <nnhubb...@gmail.com> wrote:
> Thanks James for that tip.
>
> Still looking for how to pass a var from one event function to
> another...
>
> On Aug 12, 4:28 pm, James <james.gp....@gmail.com> wrote:
>
> > I'm not sure I understand what you're trying to do with the change()
> > function...
> > You know you can get the value of a select just with val(). You don't
> > have to loop through each option to find which is selected.
>
> > <select id="mySelect">
> >     <option value="1">1</option>
> >     <option value="2">2</option>
> > </select>
>
> > var myVal = $("#mySelect").val(); // 1 or 2
>
> > On Aug 12, 1:18 pm, Nic Hubbard <nnhubb...@gmail.com> wrote:
>
> > > I am confused about how to do this the right way.
>
> > > I have a change event which grabs the value of the selected option
> > > list and sets that as a var.  But, I would like to add that to the end
> > > of my post string when I submit the form, how would I do this?
>
> > > $('select').change(function() {
>
> > >         $('select option:selected').each(function() {
>
> > >                 var my_val = $(this).val();
>
> > >         });//end each
>
> > > });//end change
>
> > > $('#my_submit').submit(function() {
>
> > >         var action = $('form').attr('action');
> > >         // How do I get my_val variable into here??
> > >         $('form').attr('action', action + 'new_parm=' + my_val);
>
> > > });
>
>

Reply via email to