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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:07:44+00:00 2026-06-16T10:07:44+00:00

The div container: <div id="count"><span>Apple:</span>4</div> The form dropdown list: <select id="list" size="6"> <option selected="selected">Any

  • 0

The div container:

<div id="count"><span>Apple:</span>4</div>

The form dropdown list:

<select id="list" size="6">
  <option selected="selected">Any Number</option>
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5+</option>
</select>

I want to tie the option list to the fruit count. If the div container has a value of "Apple:4", then "Option 4" will be selected, if the div value changes to "Pear:3" then "Option 3" should be selected, so on and so forth.

Here is what I have done so far in jQuery:

var optionObject = document.getElementById('list');
var countValue = document.getElementById("count").childNodes[2].nodeValue;
                
for(var i=0; i<optionObject.length; i++){                        
   if(optionObject.options[i].text == countValue.trim()){
        optionObject.options[i].selected = true;
        break;
   }
}

But nothing happens after execution.

  • 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-16T10:07:45+00:00Added an answer on June 16, 2026 at 10:07 am

    It works, just change the second line to:

    var countValue = document.getElementById("count").childNodes[1].nodeValue;
    

    The working jsFiddle.

    Think upon it if you have it make it work for numbers > 5 😉

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

Sidebar

Related Questions

This is my code : HTML: <div id="container"> <div id="box"> Content </div> </div>​ CSS:
Consider the following HTML/css code sample: <div id="container"> <div id="up">Text<br />Text<br />Text<br /></div> <div
Hi I've got something like the following HTML: <div class="container"> <img src="first.png" /> <img
Is there any way to disable all input fields in an div container with
I'm using Fancybox to load some content with AJAX. Content: <div class="container"> <h2>An image</h2>
I have a really simple set up: <div class="container"> <ul> <li>Item one</li> <li>Item two</li>
I have textarea and a DIV container holding that textarea. <div class="holder"> <div style="float:left;">
I have a div container, and I call it "content_container". This container is able
<div class="container"> <div class="row" style="padding-top: 240px;"> <a href="#" class="btn btn-large btn-primary" rel="popover" data-content="<form><input type="text"/></form>"
Should look like this: (source: gyazo.com ) My attempt <div class="header"> <div class="container"> <img

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.