By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Javascript Error: Object expected

P: 2
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 --

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>VAP</title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  6. </head>
  7. <body>
  8. <script type="text/javascript">
  9. function process()
  10. {
  11. if (document.calculate.case[2].checked == true) 
  12. {
  13. document.calculate.typ[0].checked=true;
  14. document.calculate.typ[1].disabled=true;
  15. }
  16. else
  17. {
  18. document.calculate.typ[0].checked=false;
  19. obj.typ[1].checked=false;
  20. obj.typ[0].disabled=false;
  21. obj.typ[1].disabled=false;
  22. }
  23. }
  24.  
  25. </script>
  26. <form method="post" action="calculate.php" name="calculate">
  27. <P>
  28. <span style="FONT-WEIGHT: bold"> Case</span>: <input onclick="proces();" name="case" value="A" type="radio"> A
  29. <input onclick="process();" name="case" value="B" type="radio"> B
  30. <input onclick="process();" name="case" value="C" type="radio">C
  31. <br>
  32. <SPAN style="FONT-WEIGHT: bold"></SPAN></P>
  33. <P><SPAN style="FONT-WEIGHT: bold">Type</SPAN>: 
  34. <INPUT type="radio" value="D" name="typ">D 
  35. <INPUT type="radio" value="E" name="typ">E </P>
  36. <P>
  37. <br>
  38. <input value="Submit" type="submit">
  39. </P>
  40. </form>
  41. </body>
  42. </html>
  43.  
Jan 12 '09 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Welcome to Bytes!

You haven't defined obj anywhere. Also, to refer to a radio button, use something like:
Expand|Select|Wrap|Line Numbers
  1. var cases = document.calculate.elements["case"];
Jan 13 '09 #2

P: 2
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.

--------------
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3.     <head>
  4.         <title>VAP</title>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  6.     </head>
  7.     <body>
  8.         <script type="text/javascript">
  9.  
  10.             function process()
  11.             {
  12.                 if (document.calculate.case[2].checked == true) 
  13.                 {
  14.                     document.calculate.typ[0].checked=true;
  15.                     document.calculate.typ[1].disabled=true;
  16.                 }
  17.                 else
  18.                 {
  19.                     document.calculate.typ[0].checked=false;
  20.                     document.calculate.typ[1].checked=false;
  21.                     document.calculate..typ[0].disabled=false;
  22.                     document.calculate.typ[1].disabled=false;
  23.                 }
  24.             }
  25.  
  26.         </script>
  27.         <form method="post" action="calculate.php" name="calculate">
  28.             <P>
  29.                 <span style="FONT-WEIGHT: bold"> Case</span>: <input onclick="process();" name="case" value="A" type="radio">
  30.                 A
  31.                 <input onclick="process();" name="case" value="B" type="radio">
  32.                 B
  33.                 <input onclick="process();" name="case" value="C" type="radio">C
  34.                 <br>
  35.                 <SPAN style="FONT-WEIGHT: bold"></SPAN></P>
  36.             <P><SPAN style="FONT-WEIGHT: bold">Type</SPAN>: 
  37.                 <INPUT type="radio" value="D" name="typ">D 
  38.                 <INPUT type="radio" value="E" name="typ">E </P>
  39.             <P>
  40.                 <br>
  41.                 <input value="Submit" type="submit">
  42.             </P>
  43.         </form>
  44.     </body>
  45. </html>
-----------------------------------
Jan 13 '09 #3

acoder
Expert Mod 15k+
P: 16,027
If you access the radio buttons using:
Expand|Select|Wrap|Line Numbers
  1. var cases = document.calculate.case;
  2. var typs = document.calculate.typ;
then use these arrays in the following way:
Expand|Select|Wrap|Line Numbers
  1. if (cases[2].checked) ...
it should solve the problem.

PS. please use [code] tags when posting code. Thanks!
Jan 14 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.