Solved

onselectedindexchanged for a list box

Posted on 2004-08-11
7
2,255 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Placeholder text not disappearing in Contact Form 7 2 23
JS does not refresh 6 30
AJAX ModalPopupExtender will Not Hide in Asp.net 1 7
Javascript 2 26
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

828 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