Note that there are some explanatory texts on larger screens.

plurals
  1. POIE9 file input is triggering wrong click event
    primarykey
    data
    text
    <p>I have some jQuery that allows the user to select all checkboxes by clicking a 'Select all' checkbox.</p> <p>My jQuery looks like this:</p> <pre><code>$('.select-all').on('click', function(){ // alert($(this).attr('name')); - For debugging checkboxes = $(this).closest('.form-item').find('input[type=checkbox]'); if($(this).attr('checked')) { $(checkboxes).prop('checked', true); } else { $(checkboxes).prop('checked', false); } }); </code></pre> <p>My 'Select all' checkbox has a class of 'select-all', which when clicked triggers this jQuery code. This all works fine.</p> <p>Further down the form there is also a file input. Now for some reason in IE9 when the file input field is clicked it's also triggering the code above. The two are not connected in any way.</p> <p>Here's my file input HTML:</p> <pre><code>&lt;div id="form&lt;?php echo $this-&gt;id; ?&gt;_file" class="form-item"&gt; &lt;label for="file" class="mandatory"&gt;&lt;span class="invisible"&gt;Mandatory field&lt;/span&gt; Select file*&lt;/label&gt; &lt;span class="clearfix"&gt;&lt;/span&gt; &lt;input id="file-input" name="file" type="file" /&gt; &lt;p class="tl_help tl_tip"&gt;Select the file to upload.&lt;/p&gt; &lt;/div&gt; </code></pre> <p>Here's the HTML of the checkboxes:</p> <pre><code>&lt;div id="form52_country" class="form-item checkbox-group"&gt; &lt;label for="country" class="mandatory"&gt;&lt;span class="invisible"&gt;Mandatory field&lt;/span&gt; Country*&lt;/label&gt; &lt;span class="clearfix"&gt;&lt;/span&gt; &lt;input class="select-all" type="checkbox" name="sa" value=""&gt;Select all&lt;br&gt; &lt;input type="checkbox" name="country[]" value="al"/&gt;Albania&lt;br&gt; &lt;input type="checkbox" name="country[]" value="ar"/&gt;Argentina&lt;br&gt; // Rest of checkboxes continue as above &lt;/div&gt; </code></pre> <p>Here's where it gets even stranger. When I uncomment the alert in the jQuery code and try clicking the file input it alerts the name of my 'select all' checkbox button.</p> <p>Any ideas what is going on here? I can't make any sense of it, it only happens in IE. It seems as if it's treating my file input field as if it were my 'Select all' checkbox field.</p> <p>Thanks</p> <p><strong>Edit - Solved</strong></p> <p>Managed to track down the cause of this. I hadn't closed one of my label tags elsewhere in the form, after fixing this the problem stopped.</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.
 

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