Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery .change() not happening when dynamically adding content to a form field
    primarykey
    data
    text
    <p>This code populates a form from an API.</p> <pre><code>$('#shipper_search').click(function(){ var searchBy = $('#shipper_search_by').val(); var searchFor = $('#shipper_search_for').val(); var warehouse = $('#warehouse').val(); $.get('index.php?p=api&amp;r=json&amp;c=location&amp;m=find&amp;d=' + searchBy + '/' + searchFor + '/shipper/' + warehouse , function(data, status){ data = $.parseJSON(data); $('#shipper_name').val(data['body'][0]['location_name']); $('#shipper_address1').val(data['body'][0]['address1']); $('#shipper_address2').val(data['body'][0]['address2']); $('#shipper_city').val(data['body'][0]['city']); $('#shipper_state').val(data['body'][0]['state']); $('#shipper_zip').val(data['body'][0]['zip']); $('#shipper_country').val(data['body'][0]['country']); $('#shipper_contact_name').val(data['body'][0]['contact_name']); $('#shipper_contact_phone').val(data['body'][0]['phone']); $('#shipper_contact_fax').val(data['body'][0]['fax']); $('#shipper_contact_email').val(data['body'][0]['email']); }); }); </code></pre> <p>Each time a field changes in that section the following code is supposed to run:</p> <pre><code>$('#shipperinfo').find('input:text').change(function(){ var valid = 0; if($('#shipper_name').val().length &gt; 0){ valid++; } if($('#shipper_address1').val().length &gt; 0){ valid++; } if($('#shipper_city').val().length &gt; 0){ valid++; } if($('#shipper_state').val().length &gt; 0){ valid++; } if($('#shipper_zip').val().length &gt; 0){ valid++; } if($('#shipper_country').val().length &gt; 0){ valid++; } if(valid == 6) { $('#shipper_ok').removeClass('hide'); } else { $('#shipper_ok').addClass('hide'); } }); </code></pre> <p>When a user manually types the information into the field, the second function works perfectly. When, however, they use the search feature to populate the form the .change() doesn't seem to happen.</p> <p>I've been searching for an age as to why, and I'm relatively new (~4 days) to jQuery/JS so I'm not sure how to begin to resolve this. Any suggestions or ideas are appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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