Solved

javascript get selected index from select using IE9

Posted on 2013-06-24
10
852 Views
Last Modified: 2013-06-25
Hi,


This javascript code was OK with previous version of IE and still is with
Fire Fox but unfortunately not with IE9


Could some one help myself, Please?????


 var cost = (indexsite .options[listecost.selectedIndex].value);


It is about a HTML select to get the selected index:


 var indexsite = document.getElementById('collabro');
   var val = (indexsite .options[collabro.selectedIndex].value).split("#");
   matricule=val[2].replace("(","");
       matricule_RO=matricule.replace(")","");
   nom_RO = val[0]+' '+val[1];  
   indexsite = document.getElementById('listecost');
   var cost = (indexsite .options[listecost.selectedIndex].value);


Thanks a lot??????????????
0
Comment
Question by:DavidInLove
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 100 total points
Comment Utility
to get the selected text, change this:
 var cost = (indexsite .options[listecost.selectedIndex].value);

Open in new window

to this:
 var cost = indexsite .options[indexsite.selectedIndex].Text;

Open in new window

0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 50 total points
Comment Utility
You have a space after indexsite
Is that a typo
0
 

Author Comment

by:DavidInLove
Comment Utility
I have tried both solutions but there is still the bugg.
It seems this code is OK just for FireFox not for IE
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
Let me check ill get back 2u
0
 

Author Comment

by:DavidInLove
Comment Utility
OK Thanks a lot
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Assisted Solution

by:Sar1973
Sar1973 earned 350 total points
Comment Utility
Try "var cost = indexsite.options[indexsite.selectedIndex].text; " (eliminate space, refer to the indexsite variable and use lowercase of the text command) and check that indexsite is not an array, otherwise you will have to refer to indexsite[j] j-element.
var cost = indexsite.value works if you are not referring to combos/array with multiple values.
0
 

Author Comment

by:DavidInLove
Comment Utility
I have tried this already but unfortunately it was not succed
var cost = indexsite.options[indexsite.selectedIndex].text
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 350 total points
Comment Utility
Take a look at http://www.w3schools.com/jsref/prop_select_selectedindex.asp if you may find the source error in your code. Please notice that you declare twice the indexsite variable.
0
 
LVL 4

Expert Comment

by:ScorchD
Comment Utility
Try separating the .split() command, just a hunch.
0
 

Author Closing Comment

by:DavidInLove
Comment Utility
This I've found in
http://www.w3schools.com/jsref/prop_select_selectedindex.asp

function displayResult()
 {
 var x=document.getElementById("mySelect").selectedIndex;
 var y=document.getElementById("mySelect").options;
 alert("Index: " + y[x].index + " is " + y[x].text);
 }
 </script>
 </head>
 <body>
 
<form>
 Select your favorite fruit:
 <select id="mySelect">
   <option>Apple</option>
   <option>Orange</option>
   <option>Pineapple</option>
   <option>Banana</option>
 </select>
 </form>
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

772 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

10 Experts available now in Live!

Get 1:1 Help Now