Solved

javascript get selected index from select using IE9

Posted on 2013-06-24
10
869 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

697 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