Solved

javascript get selected index from select using IE9

Posted on 2013-06-24
10
883 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
Independent Software Vendors: 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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…

717 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