Microsoft JScript runtime error: 'document.forms.0.cmbState.options' is null or not an object

Hi, the following code works in an aspx page when part of a <head>, but not when part of <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

var state = document.forms[0].cmbState.options[document.forms[0].cmbState.selectedIndex].text;

Can anyone help me with this ?.

Thanks in advance
LVL 1
Netlink2Asked:
Who is Participating?
 
RejojohnyCommented:
try
var state = document.getElementById('<%=cmbState.clientid%>').value;
0
 
Netlink2Author Commented:
Hi Rej,
I get the error " Microsoft JScript runtime error: Object required ".
This could be because I'm running the Javascript from a .js file. Any further ideas ?.
0
 
Netlink2Author Commented:
OK, The code works (per your response) if I copy the code in to the aspx file itself. Any way I can get it running from a .js file ?.
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.

All Courses

From novice to tech pro — start learning today.