Javascript Error: Object expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vas12
    New Member
    • Jan 2009
    • 2

    Javascript Error: Object expected

    Hi,

    I have seen emails with this particular message but they do not help me. I get this error only in IE 6 & 7. Firefox, Safari and Opera work fine.

    Can some one point out what I am doing wrong? As a result of this error, the javascript function is not getting called at all. Thanks!

    Here is the code --

    [code=html]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>VAP</title>
    <meta http-equiv="Content-Type" content="text/html;charset=IS O-8859-1">
    </head>
    <body>
    <script type="text/javascript">
    function process()
    {
    if (document.calcu late.case[2].checked == true)
    {
    document.calcul ate.typ[0].checked=true;
    document.calcul ate.typ[1].disabled=true;
    }
    else
    {
    document.calcul ate.typ[0].checked=false;
    obj.typ[1].checked=false;
    obj.typ[0].disabled=false ;
    obj.typ[1].disabled=false ;
    }
    }

    </script>
    <form method="post" action="calcula te.php" name="calculate ">
    <P>
    <span style="FONT-WEIGHT: bold"> Case</span>: <input onclick="proces ();" name="case" value="A" type="radio"> A
    <input onclick="proces s();" name="case" value="B" type="radio"> B
    <input onclick="proces s();" name="case" value="C" type="radio">C
    <br>
    <SPAN style="FONT-WEIGHT: bold"></SPAN></P>
    <P><SPAN style="FONT-WEIGHT: bold">Type</SPAN>:
    <INPUT type="radio" value="D" name="typ">D
    <INPUT type="radio" value="E" name="typ">E </P>
    <P>
    <br>
    <input value="Submit" type="submit">
    </P>
    </form>
    </body>
    </html>
    [/code]
    Last edited by pbmods; Jan 13 '09, 12:16 AM. Reason: Added CODE tags.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to Bytes!

    You haven't defined obj anywhere. Also, to refer to a radio button, use something like:
    Code:
    var cases = document.calculate.elements["case"];

    Comment

    • vas12
      New Member
      • Jan 2009
      • 2

      #3
      That is not the source of the error.

      Sorry about that. In my attempt to create a small code for people to see I made that obj error.

      Please see this. Even with the obj removed I get the expected identifier error.

      --------------
      Code:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
          <head>
              <title>VAP</title>
              <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
          </head>
          <body>
              <script type="text/javascript">
      
                  function process()
                  {
                      if (document.calculate.case[2].checked == true) 
                      {
                          document.calculate.typ[0].checked=true;
                          document.calculate.typ[1].disabled=true;
                      }
                      else
                      {
                          document.calculate.typ[0].checked=false;
                          document.calculate.typ[1].checked=false;
                          document.calculate..typ[0].disabled=false;
                          document.calculate.typ[1].disabled=false;
                      }
                  }
      
              </script>
              <form method="post" action="calculate.php" name="calculate">
                  <P>
                      <span style="FONT-WEIGHT: bold"> Case</span>: <input onclick="process();" name="case" value="A" type="radio">
                      A
                      <input onclick="process();" name="case" value="B" type="radio">
                      B
                      <input onclick="process();" name="case" value="C" type="radio">C
                      <br>
                      <SPAN style="FONT-WEIGHT: bold"></SPAN></P>
                  <P><SPAN style="FONT-WEIGHT: bold">Type</SPAN>: 
                      <INPUT type="radio" value="D" name="typ">D 
                      <INPUT type="radio" value="E" name="typ">E </P>
                  <P>
                      <br>
                      <input value="Submit" type="submit">
                  </P>
              </form>
          </body>
      </html>
      -----------------------------------
      Last edited by acoder; Jan 14 '09, 08:21 AM. Reason: Added [code] tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        If you access the radio buttons using:
        Code:
        var cases = document.calculate.case;
        var typs = document.calculate.typ;
        then use these arrays in the following way:
        Code:
        if (cases[2].checked) ...
        it should solve the problem.

        PS. please use [code] tags when posting code. Thanks!

        Comment

        Working...