?
Solved

What is the Javascript code to set a select index

Posted on 2007-07-26
4
Medium Priority
?
187 Views
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!
0
Comment
Question by:Christopher Schene
4 Comments
 

Author Comment

by:Christopher Schene
ID: 19577511
up points to 300
0
 
LVL 58

Accepted Solution

by:
amit_g earned 1200 total points
ID: 19577540
document.forms[0].Options1.selectedIndex = 2;
0
 
LVL 6

Expert Comment

by:gjutras
ID: 19577741
document.forms[0].Options1.options[document.forms[0].Options1.selectedIndex].selected=false;
document.forms[0].Options1.options[newIndex].selected=true;
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 19578262
as gjutras suggested, but some browser are still too stupid to handle the DOM, they sometimes work with:
  document.forms[0].Options1.options[document.forms[0].Options1.selectedIndex].setAttribute('selected',false);
  document.forms[0].Options1.options[newIndex].setAttribute('selected',true);

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().
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

850 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