mrpatg
mrpatg

Reputation: 10117

is it possible to have an OR statement with jquery functions?

I have the following bit of code that triggers some ajax events on a form:

jQuery('#input1').change(function(){ //bla bla bla });

For some reason, if the page refreshes (such as in a failed form submit due to invalidation), this event no longer triggers. Is it possible to fire the //bla bla bla part on change OR if the value of #input1 is whatever?

Upvotes: 0

Views: 44

Answers (2)

Russo
Russo

Reputation: 341

Are you using this?

$(document).ready(function() {
// Handler for .ready() called.
});

You can put your event here and try

Upvotes: 0

ahren
ahren

Reputation: 16961

Just inside your $(document).ready() do a conditional check:

if($("#input1").val() == "some value"){
  $("#input1").change();
  // or $("#input1").trigger("change");
}

Upvotes: 4

Related Questions