Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am getting error in javascript as "Microsoft JScript runtime error: 'options' is null or not an object "

JavaScript
var sel = document.forms[0].elements("Emp").value;
alert(sel);
var pos = sel.selectedIndex; //'Displaying "undefined
alert(pos);
var optText = sel.options[pos].text; //"Error in 'options' is null or not an object "



what is the problem...?

ADDITION:
JavaScript
function ViewAllted() {
   if(document.forms[0].Emp.value!=''){

    //var sel = document.getElementById("Emp");

    var sel = document.forms[0].elements("Emp").value;    
    alert(sel);

     var strValue = sel.options[sel.selectedIndex].value;

        alert('Sselected Value is: ' + strValue + ' and Index is: ' + sel.selectedIndex);

        var optText = sel.options[strValue ].text;

        document.forms[0].EmpName.value = optText;    
   }

	document.forms[0].action="FORMEMP.aspx?M=V"	document.forms[0].submit();
   } else {

	alert("Select an Employee!")
   }
}

<input type="button"  onclick="Javascript: ViewAlloted()" value="View Existing Allocation" />
Posted
Updated 28-Dec-11 9:07am
v4
Comments
Sunasara Imdadhusen 28-Dec-11 8:14am    
added <PRE> tag for more clarity!
thatraja 28-Dec-11 9:09am    
Show the HTML
gani7787 28-Dec-11 9:19am    
function ViewAllted() {if(document.forms[0].Emp.value!=''){

//var sel = document.getElementById("Emp");

var sel = document.forms[0].elements("Emp").value; alert(sel);

var strValue = sel.options[sel.selectedIndex].value;

alert('Sselected Value is: ' + strValue + ' and Index is: ' + sel.selectedIndex);

var optText = sel.options[strValue ].text;

document.forms[0].EmpName.value = optText; }

document.forms[0].action="FORMEMP.aspx?M=V" document.forms[0].submit();}else{

alert("Select an Employee!")}}

<input type="button" önclick="Javascript: ViewAlloted()" value="View Existing Allocation" />

1 solution

Hi Use following code to Get Selected Index

C#
var sel = document.getElementById("Emp");
var strValue = sel.options[sel.selectedIndex].value;
alert('Selected Value is: ' + strValue +' and Index is: ' + sel.selectedIndex);


Thanks,
Imdadhusen
 
Share this answer
 
Comments
gani7787 28-Dec-11 8:28am    
My sel values will be "null" when i use var sel = document.getElementById("Emp");
and also same error i am getting ""Microsoft JScript runtime error: 'options' is null or not an object "

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900