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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:23:19+00:00 2026-05-31T05:23:19+00:00

I wrote a PHP code for prepare jQuery function, which can select multipal values

  • 0

I wrote a PHP code for prepare jQuery function, which can select multipal values from the html multi select box.

there are different campaigns and it have separate question sets, the one campain has many question sets.
below code returns the output as

$('#q9 select').val('2'); 
$('#q10 select').val('2'); 
$('#q10 select').val('1');

but i need this output as

$('#q9 select').val(['2']); 
$('#q10 select').val(['2','1']);

to select multipal items, can anyone help please, thank you…

<script>
$(function(){
 <?php 

 foreach ($selectdefaults as $s):
   ?>   
   $('#q<?php echo $s['campsetjoin']['campid'];?> select').val('<?php echo $s['campsetjoin']['setid'];?>');
   <?php  
 endforeach;
 ?> 
});
</script>
  • 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-31T05:23:20+00:00Added an answer on May 31, 2026 at 5:23 am

    i agree with the above two answers that either modifying your data structure or using a pure JS solution would be cleaner. however, if neither of them are an option, you could do something like this:

    <script>
    $(function(){
     <?php 
    
     // make a hash with the campid as the key
     // and the value be an array of all of the setids
     $campids = array();
     foreach ($selectdefaults as $s):
       $quoted_setid = "'"+$s['campsetjoin']['setid']+"'";
       if ($campids[$s['campsetjoin']['campid']) {
         $campids[$s['campsetjoin']['campid']][] = $quoted_sid;
       }else {
         $campids[$s['campsetjoin']['campid']] = array($quoted_sid);
       }
     endforeach;
    
     foreach ($campids as $c=>$setids):
       ?>   
       $('#q<?php echo $c;?> select').val('[<?php echo implode(",", $setids);?>]');
       <?php  
     endforeach;
     ?> 
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this PHP code to make some substitutions: function cambio($txt){ $from=array( '/\+\>([^\+\>]+)\<\+/', //finds
I wrote some PHP code that will allow me to create an html dropdown
Can anyone have a look at the php code I wrote. I want to
I wrote a PHP code that kills the session after 5 minuets from creation.
I wrote a Facebook app from PHP and HTML that work perfect in the
I'm trying to make Jquery delete function, here is the code, that I wrote
I wrote a PHP code like this $site=http://www.google.com; $content = file_get_content($site); echo $content; But
I copied this code (in spanish) http://www.elrincondelc.com/nuevorincon/index.php?pag=codigos&id=4 and wrote a new one. This is
When writing PHP code for any given project, do you find you can write
I wrote a PHP CUrl Class, if i execute Methods which should return the

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.