?
Solved

onselectedindexchanged for a list box

Posted on 2004-08-11
7
Medium Priority
?
2,259 Views
Last Modified: 2008-03-10

When using onselectedindexchanged for a list box nothing nothing seems to be happening but the onclick is working fine.

help

davoman
0
Comment
Question by:davoman
[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
7 Comments
 
LVL 9

Expert Comment

by:ftaco96
ID: 11774055
Try using the onchange event.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11774059
Hi

You can't use onselectedindexchanged. It doesn't exist. You should use onchange instead, which has the same effect.

Regards,
Zyloch
0
 
LVL 1

Author Comment

by:davoman
ID: 11774154

Thats great i'm trying to pick up whats been tselected though. I suppose i can't use selected index either
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 36

Accepted Solution

by:
Zyloch earned 2000 total points
ID: 11774206
After you use onchange, use document.forms['FORMNAME'].selectboxname.selectedIndex to figure out what's been selected.
You can use:

var obj = document.forms["FORMNAME"].SELECT_BOX_NAME;
obj.selectedIndex;            //Same as above
obj.options[obj.selectedIndex].value      //Value of selected option
obj.options[obj.selectedIndex].text       //Text of selected option

Regards
0
 
LVL 9

Expert Comment

by:ftaco96
ID: 11774212
<select onchange="yourFunction(this.selectedIndex);">



<script>
    function yourFunction(idx) {
        //your code
    }
</script>
0
 
LVL 8

Expert Comment

by:RozanaZ
ID: 11774227
<HTML>
<HEAD>
<TITLE></TITLE>
<script>
var selectInd = -1;

function updateSelectedIndex()
{
      selectInd = document.forms[0].s1.options.selectedIndex;
}
 
function isIndexChanged()
{
      ind = document.forms[0].s1.options.selectedIndex;
      if (selectInd != ind)
      {
            alert("select index changed");
      }
}
</script>
</HEAD>
<BODY onLoad="javascript: updateSelectedIndex()">
<form name="f1" id="f1" action="127.0.0.0">
<select name="s1" id="s1" onChange="javascript: isIndexChanged()">
      <option value="1">1</option>
      <option value="2" selected>2</option>
      <option value="3">3</option>
</select>
</form>
</BODY>
</HTML>
0
 
LVL 9

Expert Comment

by:ftaco96
ID: 11774237
OR

<select onchange="yourFunction(this);">


<script>
    function yourFunction(field) {
        var val = field.value;
        var idx = field.selectedIndex;
    }
</script>
0

Featured Post

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!

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

771 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