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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:35:07+00:00 2026-05-19T14:35:07+00:00

Suposse user hits SPACE in a text -field. I want to check the value

  • 0
  1. Suposse user hits SPACE in a text -field. I want to check the value in the select -box. I use input.addEventListener('keydown', function(e)... to track the SPACE-hitting-point but how can I get the value of the select block <select id='topic'><option value="hello"></option> ...</section>?

  2. How can you stdout the value of the selected index? Cannot understand why not below.

        var el = document.getElementById("topic");
        var topicValue = el.options[el.selectedIndex].value;
    
        // PROBLEM: Won't do anything (despite inside <script> -tags)
        window.alert(topicValue);
    

where the topic is the select <select id="topic"[^>]*>[^<]*</select>.

  • 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-19T14:35:07+00:00Added an answer on May 19, 2026 at 2:35 pm

    The events work in the select, not to options but just conditional to the script.

    <html>
    <body>
    
    <script>
            function alertMe(option){
                    if(option == "saab"){
                            window.alert("you clicked saab in selec!");
                            document.getElementById("txt").value='saab!';
                    }
            }
    </script>
    
    
    <select onChange="alertMe(this.value);">
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="m"> Mercedes</option>
      <option>Audi</option>
    </select>
    
    <input type="text" id="txt" value="change me"></input>
    
    </body>
    </html>
    

    [Answers to the updated]

    1. You can access the select with document.getElementById('topic').options.selectedIndex or mySelect.options[selectedIndex].value (does not work with me). And apparently you could create a form to which you could refer by document.forms['topic'].elements[id] but not sure about this one. More.
    2. @Kosh that is irritating! Just do a dictionary = {0:"topic", 1:"hello",...,n:"topic_{n}"} and then use the getElementById('topic').selectedId as a key and forget the values. Not solved but rounded.

    [Update] I think I solved it, just el.value, no selectedIndex needed:

    <html>
    <body>
    
    <script>
    
    function printSelectValue()
    {
            var el = document.getElementById("selectOne");
            alert(el.value);
    
    }
    </script>
    
    
    <select id="selectOne" onChange="printSelectValue()"> 
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="m"> Mercedes</option>
    </select>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create own widget that will be able to interpret the text
I want to create a custom serializer in GSON that insert a key/value pair
Supose I have this string: a= hello world hella warld and I want to
Supose i have (A,B) (A,C) (A,D) (B,C) (B,D) (C,D) (D,E) in a text file.
Supose i have (A,B) (A,C) (A,D) (B,C) (B,D) (C,D) (D,E) in a text file.
I want to convert a alpha transparent png image to palette based png image.
i'm starting to make code checking the function's return value, but i'm not sure
I'm trying to use SQLite3 in PHP, and everithing was fine until I needed
I want to show a square with the 100% of the width of the
ANSWER IS MY OTHER COMMENT I have a problem, I'm sending user and password

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.