Solved

javascript get selected index from select using IE9

Posted on 2013-06-24
10
857 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
ID: 39271815
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
ID: 39271822
You have a space after indexsite
Is that a typo
0
 

Author Comment

by:DavidInLove
ID: 39273881
I have tried both solutions but there is still the bugg.
It seems this code is OK just for FireFox not for IE
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 42

Expert Comment

by:sedgwick
ID: 39273898
Let me check ill get back 2u
0
 

Author Comment

by:DavidInLove
ID: 39273901
OK Thanks a lot
0
 
LVL 9

Assisted Solution

by:Sar1973
Sar1973 earned 350 total points
ID: 39274271
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
ID: 39275580
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
ID: 39275722
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
ID: 39276666
Try separating the .split() command, just a hunch.
0
 

Author Closing Comment

by:DavidInLove
ID: 39277047
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 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

11 Experts available now in Live!

Get 1:1 Help Now