?
Solved

javascript get selected index from select using IE9

Posted on 2013-06-24
10
Medium Priority
?
895 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 400 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1400 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 1400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This article discusses four methods for overlaying images in a container on a web page
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 …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Suggested Courses

752 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