-2

Possible Duplicate:
jquery trigger - ‘change’ function

I have a radio button set called "pick_up_point" and I have a change handler to detect the radio button that is checked. In the change handler I call a function "clearFields()" which basically clears out the input fields.

function clearFields()
{
 $("#Enquiry_start_point").val("");
 $("#Enquiry_start_town").val("");
 $("#Enquiry_start_postcode").val("");
}

$("input[name='pick_up_point']").change(function()
{
 if($("input[name='pick_up_point']:checked").val() == "pick_up_airport")
 {
  $("#pick_up_airport_div").slideDown();
  $("#start_point_div").hide();
  clearFields();
 }
});

I also have a trigger which will retain the view if the form is redisplayed due to a validation error.

$('input[name=\'pick_up_point\']').trigger('change');

Now when I post the form the trigger is run and it calls the change handler, which of course runs the clearFields() function. So how can I get around this? I don't want the fields being cleared when the form is re-displayed.

3

1 Answer 1

1

Change your change function (sorry couldn't resist) to accept a parameter that tells you whether to clear fields or not.

2
  • How? Can I pass the parameter via the trigger at all?
    – MAX POWER
    Jul 16, 2010 at 21:40
  • Yes, the trigger method takes an optional second parameter that is a list of parameters to pass to the trigger method such as .trigger('change', ['arg1', 'arg2']). - "api.jquery.com/trigger"
    – RWGodfrey
    Jul 17, 2010 at 22:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.