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

The Archive Base Latest Questions

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

I have a code that selects an option after you clicked an element: You

  • 0

I have a code that selects an option after you clicked an element:

You can see the code here

function setAsSelectedOption(referrerElement){
  var clickToOptionMap = {
        'click-object-1'  :  'fireaway',
        'click-object-2'  :  'groundearth',
        'click-object-3'  :  'watermelon',
        'click-object-4'  :  'catchwind'
  };
  var optionId = clickToOptionMap[referrerElement.id];
  var optionElement = document.getElementById(optionId);

  optionElement.selected = true;
};

I’d like to run a code after this code. That code needs to simulate a click on the top option in the list and then clicks back on the last selected option.

Anyone know of such a script?

<!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>Simulate clicks on options</title>
</head>

<style type="text/css">
div
{
width:30px;
height:30px;
margin:4px;
cursor:pointer;
}

#click-object-1{background-color:#F00;}
#click-object-2{background-color:#0F0;}
#click-object-3{background-color:#00F;}
#click-object-4{background-color:#FF0;}
</style>


<body>


<form action="">

  <fieldset>

    <ul style="list-style:none;">
      <li>
        <select id="select_items_first" name="SelectItemsFirst">
          <option value="choose">Please choose</option>
          <option id="fireaway" value="xjakgd">Fire</option>
          <option id="groundearth" value="yuygas">Earth</option>
        </select>
      </li>
      <li>
        <select id="select_items_second" name="SelectItemsSecond">
          <option value="choosemore">Please choose</option>
          <option id="watermelon" value="piowqe">Water</option>
          <option id="catchwind" value="mnbvzi">Wind</option>
        </select>
      </li>
    </ul>

  </fieldset>

</form>

<div id="click-object-1" onclick="setAsSelectedOption(this)"></div>
<div id="click-object-2" onclick="setAsSelectedOption(this)"></div>

<br />

<div id="click-object-3" onclick="setAsSelectedOption(this)"></div>
<div id="click-object-4" onclick="setAsSelectedOption(this)"></div>


<script type="text/javascript">
function setAsSelectedOption(referrerElement){
  var clickToOptionMap = {
        'click-object-1'  :  'fireaway',
        'click-object-2'  :  'groundearth',
        'click-object-3'  :  'watermelon',
        'click-object-4'  :  'catchwind'
  };
  var optionId = clickToOptionMap[referrerElement.id];
  var optionElement = document.getElementById(optionId);

  optionElement.selected = true;
};
</script>


</body>
</html>

************************************ UPDATE 2011-09-14 ************************************

I made a gif to show what I’d like to accomplish:

enter image description here

  • 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-25T15:29:48+00:00Added an answer on May 25, 2026 at 3:29 pm

    You just have to add the following line to click an element: document.getElementById("yourid").click();

    In your case, it would be

    document.getElementById("click-object-1").click();
    document.getElementById("click-object-4").click();
    

    (see http://jsfiddle.net/gMZGr/1/ )

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

Sidebar

Related Questions

I have a code that removes an option element from a select multiple( <select
I have code that uses Win API function RegSaveKeyEx to save registry entries to
I have code that uses jquery.slideup and jquery.slidedown How can i know that div
I have a UISegmentControl that select nothing through IB, after the user selects the
I've got the following code that get's a URL parameter, selects an option from
Below are the options that I have in my HTML code: <label id="subn"> <select
I have a select query that currently produces the following results: Description Code Price
I have a Rails application that in the erb code, I use a select
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying 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.