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 5956711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:17:46+00:00 2026-05-22T18:17:46+00:00

I have several forms that require the use of a few multi-select boxes. (list

  • 0

I have several forms that require the use of a few multi-select boxes. (list of affiliates, list of sources, list of products, etc…) Each form could have it’s own set of multi-boxes, for whatever my clients need.

I also created a link that allows the user to “select all” the options in any of the multi-select boxes. And so far things work great! But I want to make the jquery a little more smart.

Here’s an example of what I’ve coded:

<table>
    <tr>
        <td><div id="allaffs" class="selectAll">select all</div></td>
    </tr>
  <tr>
    <td>
    <select name="affid[]" id="affid" size="15" style="width:230px;height:300" multiple="multiple">
      <option value="0" selected="selected">--no affiliate assigned--</option>
        <? while($r = mysql_fetch_array($somequerystuff)){  ?>
      <option value="<?php echo $r['affid']; ?>" selected="selected"><?php echo $r['affname']; ?></option>
      <? } ?>
    </select>   
    </td>
  </tr>
</table>

<table>
    <tr>
        <td><div id="allsources" class="selectAll">select all</div></td>
    </tr>
  <tr>
    <td>
    <select name="sourceid[]" id="sourceid" size="15" style="width:230px;height:300" multiple="multiple">
      <option value="0" selected="selected">--no source assigned--</option>
        <? while($r = mysql_fetch_array($somequerystuff)){  ?>
      <option value="<?php echo $r['sourceid']; ?>" selected="selected"><?php echo $r['sourcename']; ?></option>
      <? } ?>
    </select>   
    </td>
  </tr>
</table>

<script language="javascript" type="text/javascript">
$(document).ready(function(){

  $(".selectAll").click(function(){
    var theID = $(this).attr('id');
    if(theID=='allaffs'){ $("#affid option").attr("selected","selected"); }
    if(theID=='allsources'){ $("#sourceid option").attr("selected","selected"); }
  });

});
</script>

And this totally works. But I tend to add more multi-boxes for other filtering reasons.
I want to make the jquery detect the click event for the .selectAll class, but make it smart enough to select all options in the next available multi-box. This way I wouldn’t have to create a new line in the jquery code for the new box.

  • 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-22T18:17:47+00:00Added an answer on May 22, 2026 at 6:17 pm

    Rather than basing it on position (the next available multi-box), I would use a data attribute to store the id of the relevant multi-box.

    <div class="selectAll" data-multi-id="sourceid">select all</div>
    

    Then in your script:

    <script language="javascript" type="text/javascript">
        $(document).ready(function(){  
            $(".selectAll").click(function(){    
                var multi = $(this).data('multi-id');
                $('#' + multi + ' option').attr('selected', 'selected');
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form UI whereby several sections require duplicate HTML select list to
I have several .NET Windows Forms applications that I'm preparing to convert into a
I have a website with several forms that all pass the same set of
I have a page that has several ajax submission forms. Each form has a
In the company that I work for we have several web-based applications that require
I have several contact forms, which all use the same method to to validate
I have form that displays several keywords (standard set of choice lists that changes
I'm trying to put together a form_tag that edits several Shift objects. I have
I have an InfoPath form with several fields on, the problem is that one
I have several forms like this: <table width=100% border=0 cellpadding=0 cellspacing=0 class=table_std> <tr id=exam_String_newValue_row>

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.