Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4546210
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:55:23+00:00 2026-05-21T15:55:23+00:00

I have jQuery Tabs in which each tab and corresponding content are populated by

  • 0

I have jQuery Tabs in which each tab and corresponding content are populated by a PHP foreach loop.

For each tab the user can upload a picture. I have this setup in a way so that as soon as the user chooses a file, a jquery script makes the upload begin automatically — and the browse button is hidden and replaced by “Uploading your picture”.

Here is the code (CI markup):

<ul class="tab_header">
    <?php foreach ($p as $row):
        echo '<li>
            <a href="#tabs-'. $row->p_id . '">' . $row->p_name . '</a>
               </li>'; 
        endforeach; ?>
</ul>
<?php foreach ($p as $row): ?>
    <div id="tabs-<?php echo $row->p_id; ?>">

        <?php echo form_open_multipart('/p/p_upload_picture/' . $row->p_id, 'id="upload_form"');
        echo form_upload('userfile', '', 'id="file_select"');
        echo form_hidden('upload','upload');
        echo form_close(); ?>
         <div id="loading" style="display:none;">
            Uploading your picture...
         </div>     
</div>

<?php endforeach; ?>

<script>
$(function(){
    $("#file_select").change(function(){
        $("#upload_form").submit();
        $("#upload_form_div").hide();
        $("#loading").show();
    });
});
</script>   

This works perfectly but only on the first tab.

In all other tabs, the jquery script doesn’t run — as soon as I choose a file, the file name is shown in the browse button field instead, and no upload happens (form isn’t submitted).

I wonder if this has to do with the script not being initialized for the other tabs.

How can I fix this?

Thanks for helping, much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:55:24+00:00Added an answer on May 21, 2026 at 3:55 pm

    Your field has an id. Which should be unique per element.

    jQuery only returns the first element it encounters with the given id, that’s why your code isn’t working. I would suggest adding a class instead of an id to your field.

    $('.class-of-field')..change(function() {
        ..
    });
    

    The above should do the job.

    This would be the equivalent code without jQuery:

    var el = document.getElementById('file_select');
    

    Which only returns one element, have a look at the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set of Jquery-UI-Tabs which contains a save button for each tab. I
I have a page with jquery tabs in which the user can update their
I have jquery tabs, in which one tab has an iframe and the other
I have a jQuery tab script that gets content from a PHP file defined
I have tricky problem which I can't completely understand. It's jQuery tabs with cookie
I have a set of jQuery UI tabs that each load project.php using ajax.
I have an aspx page on which I have 2 static jquery tabs.Upon clicking
I have an ASP.NET MVC view on which I've placed jQuery tabs. I'm loading
I have some tabs using jQuery UI which work just fine, but I want
I have different php output in jQuery-based tabs. This output is formed from database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.