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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:54:18+00:00 2026-06-17T06:54:18+00:00

I have a form which is largely populated by checkboxes. The checkboxes each have

  • 0

I have a form which is largely populated by checkboxes. The checkboxes each have an ID “value” that corresponds to an item within a javascript array. The array items hold some text that will populate a textarea.

I would like to include some dropdown boxes to clean up the site; however, I cannot seem to assign an array ID to the dropdown options? Can this be done in a selectbox option? Is there a workaround to simulate a selectbox without using the tab?

My html is basically:

    <div>
    <input type=checkbox id=array1 name=textArray></input>
    <input type=checkbox id=array1 name=textArray></input>
    <input type=checkbox id=array1 name=textArray></input>
    ...
    <select><option 1><option 2>...</select>
    </div>
    <div>
    <form>
    <textarea id=outPut></textarea>
    </form>
    </div>

And my js is:

var textArray = {

array1: 'some text here',
array2: 'some more text',
array3: 'some other text',
...
array90: 'the last text'

};

// variable assigned to chosen item
var selectedInputs = document.getElementsByName("textArray");
for (var i = 0; i < selectedInputs.length; i++) {
    selectedInputs[i].onchange = function() {
        chosenItem = this;
        printText();        
    };
}
// Script to add items to the Comments section text area
var mytextbox = document.getElementById('outPut');
var chosenItem = null;

function printText(){
    if(chosenItem !== null){
       mytextbox.value += textArray[chosenItem.id] + "";
        // resets the radio box values after output is displayed
        chosenItem.checked = false;
        // resets these variables to the null state
        chosenItem = null;
    }
}

How can I associate an item in my js array with one of the selectbox choices?

  • 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-17T06:54:19+00:00Added an answer on June 17, 2026 at 6:54 am

    I found it very difficult to understand what you’re asking but I threw this together and hopefully it’ll be helpful.

    Important bit is

    var selectNode = document.getElementById('select'); // <select id="select">
    selectNode.onchange = function () {
      if (selectNode.selectedIndex !== 0) {
        chosenItem = selectNode.options[selectNode.selectedIndex];
        selectNode.selectedIndex = 0;
        printText();
      }
    }
    

    and not to use the id attribute for what you’re doing (I used data-i).


    I’d also like to say that if you’re cleaning up code this would be a good time to strongly reconsider how you’re passing variables between functions; setting a value in the global namespace and relying on it in the next invocation is just asking for trouble (race conditions, conflicts with other bits of code, etc).

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

Sidebar

Related Questions

I have form fields which are checkboxes as below : <input id=abirrules@gmail.com type=checkbox checked=checked
I have a form which contains a whole bunch of checkboxes and some other
I have a form which has a ListView and buttons to add/edit/delete items from
I have a form which is an MDI container. In that form i generate
I have a form which contains several checkboxes align vertically in a div. I
I have a form which is posting an array which looks like this: Array
I have a form which I want to be 'resusable' for a variety of
I have a form which has a RichTextBox docked to the left and DataGridView
I have a form which POST's its data via AJAX: $.ajax({ type: POST, url:
I have a form which has three inputs when the page loads -- 2

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.