Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object doesn't support Property or Method Error

Status
Not open for further replies.
Oct 15, 2003
145
US
I have to be doing something very simple wrong; and I can't figure out what it is...

I have a page that has a textbox and a checkbox. If the check box is checked, i want to enable the textbox. if I uncheck the check box, then the textbox should be disabled.

my javascript code is:
Code:
<body>
<script lang=javascript>
   function onClickEnableDisable() {
      if (document.getElementByID('chkOvrdCrdRpt').checked == true) {
      alert('here')
         document.getElementByID('txtScore').disabled = false;
      } else { 
         document.getElementByID('txtScore').disabled = true;
      }
   }
</script>

    <form id="form1" runat="server">
    <div>
    <input id="chkOvrdCrdRpt" type="checkbox" name="chkOvrdCrdRpt" onclick="onClickEnableDisable();" /><label for="chkOvrdCrdRpt">Override <br />
        <br />
    </label>
    <input name="txtScore" type="text" value="0" id="txtScore" disabled="disabled" tabindex="70" class="TextboxSmall" /> 
    </div>
    </form>
</body>

I'm getting an error on the very frist line of my script -- if (document.getElementByID('chkOvrdCrdRpt').checked == true)

The error is:
Microsoft JScript runtime error: Object doesn't support this property or method
 
getElementByI[blue]D[/blue] should be getElementByI[red]d[/red].

Javascript is case sensitive.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Oh my gosh - THANK YOU SO MUCH!!!!! I know it's case sensitive - and I have been staring at this code for so long - I never even noticed that capital D....

THANK YOU!!!!
 
Apart from the getElementByID error, you could try using the style visibility property instead, it seems to work better cross-browser.

document.getElementById( 'txtScore' ).style.visibility = "visible";
document.getElementById( 'txtScore' ).style.visibility = "hidden";
 
JA3395 said:
Apart from the getElementByID error, you could try using the style visibility property instead, it seems to work better cross-browser.

Perhaps you can explain:

1) How setting the visibility property is any more cross browser compliant than disabling the field, and

2) How setting the visibility property solves the problem at hand, i.e. enabling and disabling a text field.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
BillyRayPreachersSon said:
Perhaps you can explain:

1) How setting the visibility property is any more cross browser compliant than disabling the field, and

2) How setting the visibility property solves the problem at hand, i.e. enabling and disabling a text field.

Dan

I was going to ask the same things.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top