What is the Javascript code to set a select index

Posted on 2007-07-26
Last Modified: 2010-04-16
What is the Dom code to set this select index

<SELECT onchange="someJavaScriptcode" size=1 name=Options1 index="2"><OPTION selected>Actions<OPTION>View<OPTION value=P>Print<OPTION value=F>Fax</OPTION></SELECT>

I tried

document.forms.listing.Options1.index = 2;

without success

Thanks: I need a fast answer: 300 points!
Question by:cschene

    Author Comment

    up points to 300
    LVL 58

    Accepted Solution

    document.forms[0].Options1.selectedIndex = 2;
    LVL 6

    Expert Comment

    LVL 51

    Expert Comment

    as gjutras suggested, but some browser are still too stupid to handle the DOM, they sometimes work with:

    Keep in mind that forms[0] depend on your number of forms in the page, I'd use an id= attribute for the select tag and the get this object with document.getElementById().

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Introduction (All good things must come to an end ( The original MySQL API ( has gone away, deprecated by PHP in Version 5.5, and removed from PHP in all curre…
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now