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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:48:05+00:00 2026-05-28T05:48:05+00:00

I have two droplist in html built using tag. <select name=List1 id=List1 onclick=GetVal()> <option

  • 0

I have two droplist in html built using tag.

<select name="List1" id="List1" onclick="GetVal()">
<option value="1" selected="selected">Mercurio</option>
<option value="2">Venus</option>
<option value="3">Tierra</option>
<option value="4">Marte</option>
</select>

<select name="List2" id="List2">
<option value="1" selected="selected">Hg</option>
<option value="2">Ve</option>
<option value="3">Ti</option>
<option value="4">Ma</option>
</select>

I have written a script such as the selection of an element from List2 relies on the selection of the corresponding element of List1.

    <script language="javascript" type="text/javascript">
// <!CDATA[
function GetVal() {
var LSelect1 = document.getElementById('List1');
var LSelect2 = document.getElementById('List2');
switch (LSelect1.selectedIndex)
{
case 1:
  LSelect2.selectedIndex = 1;
  break;
case 2:
  LSelect2.selectedIndex = 2;
  break;
case 3:
  LSelect2.selectedIndex = 3;
  break;
default:
  LSelect2.selectedIndex = 4;
}
}
// ]]>
</script>

However, the function works wrongly for the first element of the List1. Why?

  • 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-28T05:48:06+00:00Added an answer on May 28, 2026 at 5:48 am

    selectedIndex is 0-based. A simpler way to do things might be like this:

    <script language="javascript" type="text/javascript">
    // <!CDATA[
    function GetVal() {
        var LSelect1 = document.getElementById('List1');
        var LSelect2 = document.getElementById('List2');
    
        LSelect2.selectedIndex = LSelect1.selectedIndex;
    }
    // ]]>
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two applications written in Java that communicate with each other using XML
I have two elements: <input a> <input b onclick=...> When b is clicked, I
I have two columns, senderUserID and recieverUserID in Messages table. I select senderUserID and
Have two bean definitions: file a.xml <bean id=A class=com.A> <property name=bClass ref=B/> </bean> file
Have two variables both containing integers: var input; var value; Need to perform arithmetic
I have two strings both with value null . But when I am comparing
I have two lists: List<int> listA List<int> listB How to check using LINQ if
I have two combobox in my form, using a mysql connection to a remote
Have two folders with approx. 150 java property files. In a shell script, how
I have two arrays of animals (for example). $array = array( array( 'id' =>

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.