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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:01:29+00:00 2026-05-25T14:01:29+00:00

When you click a certain element, an option will be selected. For example: you

  • 0

When you click a certain element, an option will be selected.

For example: you click on a Div element with id=”object3″, this action will automatically select the Option element “Item 3”.

Anyone know a Javascript that can do this?

HTML example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Click tag will select option</title>
</head>

<body>


<form action="">

  <fieldset>

    <ul style="list-style:none;">
      <li>
        <select id="select_items" name="SelectItems">
          <option value="Item1">Item 1</option>
          <option value="Item2">item 2</option>
          <option value="Item3">Item 3</option>
          <option value="Item4">item 4</option>
        </select>
      </li>
    </ul>

  </fieldset>

</form>

<div id="object1" style="background-color:#F00;width:30px;height:30px;margin:4px;cursor:pointer;"></div>
<div id="object2" style="background-color:#0F0;width:30px;height:30px;margin:4px;cursor:pointer;"></div>
<div id="object3" style="background-color:#00F;width:30px;height:30px;margin:4px;cursor:pointer;"></div>
<div id="object4" style="background-color:#FF0;width:30px;height:30px;margin:4px;cursor:pointer;"></div>


</body>
</html>
  • 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-25T14:01:29+00:00Added an answer on May 25, 2026 at 2:01 pm

    You can define onclick event handler for each div ( in HTML onclick="doSelect( this )" or by dynamic binds )

    function doSelect( el ) {
        var sel_id = el.id.replace( 'object', '' );
        document.getElementById( 'select_items' ).value = 'Item' + sel_id;
    }
    

    Version with id’s

    var relations = { 'object1': 'item-fire', 'object2': 'item-earth', 'object3': 'item-water', 'object4': 'item-wind' };
    
    function doSelect( el ) {
        document.getElementById( relations[ el.id ] ).selected = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DIV element that appears when a certain action is performed. For
When I click on a div element of a certain class, I change contenteditable
Click on this link , you will be redirected to a shopping site. On
I have this situation where i want to call a certain element depended on
I usually implement click event bound to a certain visual element, like final Button
I wrote a function that, on clicking a certain element, would replace a div
I use a click event for an element with certain class. Inside the click
How can I remove certain element inside html()? For instance, I have this html
I have an iPhone app with a tableviewcontroller. When you click a certain cell
How do I check for a click on everything but a certain object? I

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.