Link to home
Start Free TrialLog in
Avatar of dawesley
dawesleyFlag for United States of America

asked on

Getting error: Microsoft JScript runtime error: Object doesn't support this property or method

I'm programming in Visual Studio 2005.
I have an web page with an HTML (not ASP HTML) dropdownlist object.
I can't use 'runat=server' on the dropdownlist because it contains literals
and Microsoft won't accept them.
I want to return the value of the dropdownlist to the ASP server.
To do this, I'm trying to store the value of the dropdownlist in a hidden text field.
 
The dropdownlist HTML looks like this (not showing entire list)

       <SELECT id=ddlCountry size=1 name=country_origin onchange='storeValue(this)'
            Style="z-index: 130; left: 416px; position: absolute; top: 328px">
            <OPTION selected>Select
            one</OPTION>
            <OPTGROUP label="North American Countries">
            <OPTION value="United States">United
            States</OPTION>
            <OPTION value=Canada>Canada</OPTION>
            <OPTION value=Mexico>Mexico</OPTION>
            </OPTGROUP>
        </SELECT>...

The hidden text field is:
       <input id="hdnCountry" style="z-index: 131; left: 288px; position: absolute; top: 464px"
            type="hidden" runat=server/>

The script that I'm running in the onchange event of the dropdownlist is:
        <script type="text/javascript">
           function storeValue(what)
           {
           document.getElmentById('hdnCountry').value = what.value
           }
        </script>

When I select a value from the dropdownlist, I get the following error in the
Java script: Microsoft JScript runtime error: Object doesn't support this property or method

Much thanks to anyone who can help.


 
       
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hielo is correct. You will also have problems with not putting values in quotation marks.  See Canada and Mexico.

-LTCJ
change this:
document.getElementById('hdnCountry').value = what.value

to this:
document.getElementById('hdnCountry').value = what.options[what.selectedIndex].value
@basicinstinct:
The issue is the typo on document.getElementById.
dawesley mistyped it as:
document.getElmentById

what.value will work fine.
>>I can't use 'runat=server' on the dropdownlist because it contains literals
and Microsoft won't accept them
what do you mean? all the values seem to be acceptable in a dropdownlist too

anyway .. for getting values of this at the server, you do not need to store it in hidden field and then access it .. you can gve this a try on the server side code
request.form("ddlCountry")
or request("dllCountry") ..

this should give you the last selected value in the HTML control ..

Rejo