Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to disable .change function when the page loads
    text
    copied!<p>In my <code>$(document).ready()</code> function I have a <code>.change</code> event bound to a set or radio buttons. If there is an error on the form the user submits, however, the page will re-load with the values selected by the user. This is causing the radio button <code>.change</code> function to fire every time the page loads, which I do not want it to do. How would I disable this? </p> <p><strong>EDIT</strong></p> <p>Here's the full function, didn't post prior due to the fact it's a hot mess in the middle right now and was trying to keep the readability of this post in mind. </p> <p>FYI - If there has been an error after the user submits the form then I need the page to load the form as it was when the user hit the submit button. Since we display a certain set of <code>div</code> and <code>span</code> elements based on the radio button selection, I used the <code>trigger('change')</code> method. Is there any way to detect if the operation is occurring during a page load? </p> <pre><code> $('input[name=TransactionType]').change(function (e) { //Clear any messages from previous transaction $('.error').text(''); $('.success').text(''); //Display fieldset Submit and Cancel(back to search) link $('#PageDirection').show(); $('#AgentInformation').show(); //Display input fields var radioValue = $(this); if (radioValue.attr('id') == "Enroll" || (radioValue.attr('id') == "ModT")) { //Enable and disable input boxes $('span').not('#AllInput').hide(); $('#AllInput').show(); $('#PayFrequency').show(); $('#refNumberInput').show(); //Set tooltips $('#AccountType').removeAttr("title"); if (radioValue.attr('id') == "Enroll") { $('#PaymentFrequency').removeAttr("title"); $('.req').show(); $('#refNumberInput').show(); $('#enrollNote').show(); } else { $('#PaperStatement').show(); $('#PaymentFrequency').attr("title", "Select the frequency to pay the distributor"); $('#refNumberInput').show(); } } else if (radioValue.attr('id') == "New") { $('span').not('#NewMessage').hide(); $('#NewMessage').show(); $('.req').show(); $('#refNumberInput').show(); } else if (radioValue.attr('id') == "ModA") { $('#AllInput').show(); $('#AgentIdSpan').show(); $('.req').show(); $('#UnenrollMessage').hide(); $('#NewMessage').hide(); $('#PayFrequency').hide(); $('#PaperStatement').hide(); $('#refNumberInput').show(); $('#AgentId').attr("title", "Enter the Agent ID to be modified"); } else if (radioValue.attr('id') == "Clone") { $('span').not('#AgentIdSpan').hide(); $('#AgentIdSpan').show(); $('.req').show(); $('#AgentId').attr("title", "Clone EFT onto this Agent ID"); } else if (radioValue.attr('id') == "Unenroll") { $('span').not('#UnenrollMessage').hide(); $('#UnenrollMessage').show(); $('.req').show(); $('#refNumberInput').show(); } if (radioValue.attr('id') != "Clone") { $('.alwaysReq').show(); }; }).filter(':checked').trigger('change'); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload