• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2274
  • Last Modified:

onselectedindexchanged for a list box


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

help

davoman
0
davoman
Asked:
davoman
1 Solution
 
ftaco96Commented:
Try using the onchange event.
0
 
ZylochCommented:
Hi

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

Regards,
Zyloch
0
 
davomanAuthor Commented:

Thats great i'm trying to pick up whats been tselected though. I suppose i can't use selected index either
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ZylochCommented:
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
 
ftaco96Commented:
<select onchange="yourFunction(this.selectedIndex);">



<script>
    function yourFunction(idx) {
        //your code
    }
</script>
0
 
RozanaZCommented:
<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
 
ftaco96Commented:
OR

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


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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now