Solved

onselectedindexchanged for a list box

Posted on 2004-08-11
7
2,252 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
7 Comments
 
LVL 9

Expert Comment

by:ftaco96
Comment Utility
Try using the onchange event.
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
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
Comment Utility

Thats great i'm trying to pick up whats been tselected though. I suppose i can't use selected index either
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
Comment Utility
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
Comment Utility
<select onchange="yourFunction(this.selectedIndex);">



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

Expert Comment

by:RozanaZ
Comment Utility
<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
Comment Utility
OR

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


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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now