Thanks, Jason! It works perfectly, and I'll look into another way to
store the base_urls..i'm also not too happy with a custom attribute...

On Nov 16, 9:21 pm, Jason Huck <[EMAIL PROTECTED]> wrote:
> This line is the likely culprit, because the css selector is not
> specific to an individual <select> element:
>
>       var selected = $("select option:selected").val();
>
> Try this instead, to constrain the selection within the current
> context:
>
>       var selected = $("option:selected", this).val();
>
> Or, IIRC, I believe this works nowadays as well:
>
>       var selected = $(this).val();
>
> You might also consider storing the base URLs in an associative array
> rather than relying on custom (non-validating) attributes.
>
> HTH,
> Jason
>
> On Nov 16, 3:08 pm, Fluffy Convict <[EMAIL PROTECTED]> wrote:
>
> > I'm trying to attach a function to all selects that have the custom
> > goto-attribute. It works for the first one, but the behavior isn't
> > being attached to the second <select>. Any ideas how to fix it?
>
> > $(document).ready(function() {
> >   $('select[goto]').each(function () {
> >     $(this).change(function () {
> >       var selected = $("select option:selected").val();
> >       if (selected != 'ignore') {
> >         document.location = $(this).attr("goto") + '/' + selected;
> >       }
> >     });
> >   });
>
> > });
>
> > // with html:
>
> > <select goto="www.cnn.com">
> >   <option value="ignore">Choose...
> >   <option value="finance">CNN Finance
> >   <option value="sports">CNN Sports
> > </select>
>
> > <select goto="www.bbc.co.uk">
> >   <option value="ignore">Choose...
> >   <option value="finance">BBC Finance
> >   <option value="sports">BBC Sports
> > </select>

Reply via email to