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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:47:44+00:00 2026-06-14T14:47:44+00:00

Alright, so this question has definitely been asked before, and I was actually able

  • 0

Alright, so this question has definitely been asked before, and I was actually able to find an answer to my question in jquery and when I tried to implement the answer I couldn’t get it to work. I would just rather do it in java-script so…..

I’m reading a string of text separated by commas from a DB, and I want to translate those into selected options in a multiselect box.

All I’ve been doing up to this point is trying to get the browser to select a single option which matches a hard-coded string when I click a button but I can’t even get that to work. But I figured that since I’m asking the question, I might as well write out the whole script so you can see it all and maybe catch any other problems I can expect to have…lastly, how can I get this to run on the page’s load? Sorry if this is redundant and rudimentary but I’m very new to JS and finding existing answers to questions to be of little help. Thanks in advance.

EDIT

So, I found that I can get the assignment to work if I use ‘select.options[i].value=true’ (boolean instead of string) per Asad’s answer. However, I am using Harvest’s Chosen multiple select control: http://harvesthq.github.com/chosen/

The script will not work when I have assigned the chosen class to the control. I know that the control is calling on JQuery, is this the reason why? Is it possible to get it to work? Thanks again.

function selectitems() {
  var select = document.getElementById("multiselectid");
  var array = stringFromDB.split(",");

  for(count=0, count<array.length, count++) {
    for(i=0; i<select.options.length; i++) {
      if(select.options[i].value == array[count]) {
        select.options[i].selected="selected";
      }
    }
  }
}
  • 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-06-14T14:47:45+00:00Added an answer on June 14, 2026 at 2:47 pm

    Your first for loop has two syntax errors. Try checking the console in your browser

    for(count=0, count<array.length, count++) {
    

    should be:

    for(count=0; count<array.length; count++) {
    

    Notice the change of “,” to “;” after the count=0 and count<array.length parts.

    Also, you might want to use for(var count=0 and for(var i=0 so that the count and i variables are not declared globally.

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

Sidebar

Related Questions

Alright, I know this question has been asked before, but mine has a different
Alright, I'm not sure if this question has been asked before so if it
This has been asked before (question no. 308581) , but that particular question and
Alright, I guess this question has been asked a lot of times here. I
Alright, I understand that this problem has been asked a lot of times at
This question has been asked here in one form or another but not quite
Alright so this problem has been breaking my brain all day today. The Problem:
Alright, I know questions like this have probably been asked dozens of times, but
Alright, so I've looked around the web and haven't been able to find what
Alright, it has been a long couple of days trying to figure this out

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.