1

THis is how i am trying (no firebug errors) to restore each select of my form to its first option value

/* $(this) is the form */
$(this).find('input[type="text"],textarea').val(''); /* This works */
$(this).find("select").each(function(){
    $(this).val($(this,"option:first").val());  /* this doesnt do anything */
});

what am i doing wroing?

-edit-

just found out.. this works, why not with the comma?

$(this).val($(this).find("option:first").val());
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

1 Answers1

1

Just try this:

$(this).find("select").change();

This will automatically set the first option value as default.

If you use you code you need:

$(this).find("select").each(function(){

    $(this).val($("option:first", this ).val());  /* this doesnt do anything */

                                   ^--- this will places here

});

Your $(this, "option:first") not worked because you code is searching a select within a option, but it should search option within search.

One format of jquery selector is

$(target, context);
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164