Disabling elements on load

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob

    Disabling elements on load

    Does anybody see anything wrong ith this code? I want to have the
    elements disabled on load by default and it doesn't seem to work this
    way.

    Thanks
    Rob

    <script language="Javas cript">
    <!--
    window.onload(D isableElements( ));

    function DisableElements (){
    document.forms[0].RepContactDemo graphic_2_1.dis abled = true;
    document.forms[0].RepFlightTrave lArriveDate_1.d isabled = true;
    document.forms[0].RepFlightTrave lDepartDate_1.d isabled = true;
    document.forms[0].RepContactDemo graphic_3_1.dis abled = true;
    document.forms[0].RepContactDemo graphic_4_1.dis abled = true;
    document.forms[0].RepDepartureCi ty_1.disabled = true;

    }

    //-->
    </script>



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Lasse Reichstein Nielsen

    #2
    Re: Disabling elements on load

    Rob <rvenable@hotma il.com> writes:
    [color=blue]
    > Does anybody see anything wrong ith this code? I want to have the
    > elements disabled on load by default and it doesn't seem to work this
    > way.[/color]
    ....[color=blue]
    > <script language="Javas cript">[/color]
    Should be
    <script type="text/javascript">
    The type attribute is required by HTML 4, and is always sufficient.
    [color=blue]
    > <!--[/color]

    HTML-comments are not needed here.
    [color=blue]
    > window.onload(D isableElements( ));[/color]

    This code immediately calls the window's onload property with an
    argument that is the return value of calling DisableElements .
    What you probably meant was:
    ---
    window.onload = DisableElements ;
    ---
    There should be no calling of functions yet.
    [color=blue]
    > function DisableElements (){
    > document.forms[0].RepContactDemo graphic_2_1.dis abled = true;
    > document.forms[0].RepFlightTrave lArriveDate_1.d isabled = true;[/color]

    I would create a variable referring to the form (or event its elements
    collection) insted of finding it froms cratch for each line:

    var formElems = document.forms[0].elements;
    formElems['RepContactDemo graphic_2_1'].disabled = true;
    formElems['RepFlightTrave lArriveDate_1'].disabled = true;
    ...

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Rob

      #3
      Re: Disabling elements on load


      Thank you, works like a charm.

      Rob


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...