Solved

onselectedindexchanged for a list box

Posted on 2004-08-11
7
2,257 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 36

Accepted Solution

by:
Zyloch earned 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

691 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