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

  • Home
  • SEARCH
  • 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 8153175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:55:47+00:00 2026-06-06T15:55:47+00:00

The below code doesn’t it print the value. function go(x) { alert(x.options.selectedIndex.value); //location=document.menu.student.options[document.menu.student.selectedIndex].value }

  • 0

The below code doesn’t it print the value.

function go(x)
{
   alert(x.options.selectedIndex.value);
   //location=document.menu.student.options[document.menu.student.selectedIndex].value
}

this is the html code

<select name="student" onChange="go(this)">
    <option selected> Student </option>
    <option value="http://www.cnet.com">Attendence</option>
    <option value="http://www.abc.com">Exams</option>
</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-06-06T15:55:49+00:00Added an answer on June 6, 2026 at 3:55 pm

    selectedIndex is a number, it doesn’t have a value property.

    If you have a select element which just allows single-select (as yours does), the easiest way to get its value is the select element’s value property:

    function go(x) {
        alert(x.value);
    }
    

    Double-check that it works on the browsers you want to support, but MaryAnne (see the comments) has checked on all current major browsers and I’ve checked IE6, IE7, and Firefox 3.6 (e.g., older browsers), and they all work. Since it’s specified in DOM2 HTML (the link above)…

    But re selectedIndex, you probably meant:

    function go(x) {
        alert(x.options[x.selectedIndex].value);
    }
    

    I’d probably take it a bit further and be more defensive:

    function go(x) {
        var option = x.options[x.selectedIndex];
        if (option) {
            alert(option.value);
        }
    }
    

    …or

    function go(x) {
        var option = x.options[x.selectedIndex];
        var value = option && option.value;
        alert(value); // Alerts "undefined" if nothing is selected
    }
    

    …in case there is no selected option (in which case, option will be undefined), although with your particular markup and code, I’m not aware of a user agent where the change event would be fired without there being anything selected. At least, I don’t think so — “I think” being the reason for being defensive. 🙂

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

Sidebar

Related Questions

The code below doesn't seem to work //javascript function t_show() { if(document.getElementById(t_show).checked == true){
This code below doesn't work correctly since my MFC program is in unicode circumstance.
UPDATE: I've posted the Renderer code below, since this code here doesn't seem to
Code below doesn't work on any browser. It's supposed to show an alert box.
The code below doesn't seem to work or find anything on an array. I'm
Could anyone help me in assessing why the code below doesn't work. I'm using
My code below seems logical however i don't know why the sorting doesn't work
with asp.net code below my ajax_loader image doesn't work well and always shown ..
In the code below, the image imgNew doesn't show on the canvas when I
In the below code how does passing bar as function (n) { return n;

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.