473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

error: object expected

9
hi,
hoping i have posted this in the right section this time :)
i am doing my javascript still, and cant figure out why i keep getting an error: object expected message for validateform()
im just not sure what i have done wrong with it, i have tried to give it a function, just cant find where my mistake is. any help would be greatly appreciated, thanks :)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>activity 2.22</title>
  4. </head>
  5. <script type="text/javascript">
  6. function validateform()
  7. {
  8.   var element;
  9.   var BikeMoney;
  10.   var TVMoney;
  11.   var iPodMoney;
  12.   var CarPrice;
  13.   var flag="OK";
  14.   element=document.getElementsByTagName('input');
  15.   for (counter=0; counter<element.length; counter++)  
  16.     {
  17.       switch (element[counter].type)
  18.         {
  19.           case "submit":
  20.           break;
  21.           default:
  22.           if(isNaN(element[counter].value))
  23.             {
  24.               alert("You need to enter a number into " + element[counter].name);
  25.               var flag="NotOK";
  26.             }
  27.           else
  28.           {
  29.             BikeMoney=element[0].value;
  30.             TVMoney=element[1].value;
  31.             iPodMoney=element[2].value;
  32.             CarPrice=element[3].value;
  33.           }
  34.         }
  35.     }
  36. }
  37. if (var flag=="OK")
  38.   {
  39.     TotalMoney = parseFloat(BikeMoney) + parseFloat(TVMoney) + parseFloat(iPodMoney);
  40.       if (TotalMoney >= CarPrice)
  41.         {
  42.           alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you can afford the car");
  43.         }
  44.     else
  45.         {
  46.           alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you cannot afford the car");
  47.         }
  48.   }
  49. </script>
  50. <body>
  51. <form name="inputform" method="post" action="">
  52. <table>
  53.   <tr><td>Enter money from bike sale</td><td><input type="text" name="Bike Money"></td></tr>
  54.   <tr><td>Enter money from TV sale</td><td><input type="text" name="TV Money"></td><tr>
  55.   <tr><td>Enter money from iPod sale</td><td><input type="text" name="iPod Money"></td><tr>
  56.   <tr><td>Enter the price of the car</td><td><input type="text" name="Car Price"></td></tr>
  57.   <tr><td></td><td><input type="submit" value="Submit Details" onclick=validateform();
  58. </table>
  59. </form>
  60. </body>
  61. </html>
Nov 10 '09 #1
7 2929
Dormilich
8,658 Expert Mod 8TB
your problems are line #36 and #37.

on line #36 you end the function and the remaining code is not executed onclick, but immediately.

on line #37 you simply have a syntax error (even if this were valid, it would always evaluate to false)

PS. I didn’t get an object expected error…

PPS. please don’t use tables to layout your form, that’s outdated. a better approach

PPPS. there’s room for improvement, because you assign the input values four times (i.e. in every loop cycle) (where once is enough)
Nov 10 '09 #2
Ibys
9
ok, I think I have fixed the first error you mentioned, but how would you recommend i fix the syntax error? not too sure what I have done wrong with that line, as it was in the instructions for how to complete the code, to insert an 'if' statement with "if flag=="OK"", then to put in the coding that is below to make the correct alert come up, which worked in the more simple code i copied it from.

I have found I only get an object expected error when using internet explorer, I only get a syntax error with firefox. Im only using the table format as this is what im being assessed on in this module, but thanks for the link, I know to use that later on now :)
Nov 10 '09 #3
Dormilich
8,658 Expert Mod 8TB
@Ibys
compare
Expand|Select|Wrap|Line Numbers
  1. if (var flag == "OK") // your code
with
Expand|Select|Wrap|Line Numbers
  1. if (flag == "OK") // instruction code
Nov 10 '09 #4
Ibys
9
ok i have managed to fix it now, i went back through until i could figure out what i had done wrong, i had been trying to declare it as a variable again, while sking it in an if statement- still only a beginner, so i still am making silly little mistakes :) thanks for the help!!
Nov 10 '09 #5
Dormilich
8,658 Expert Mod 8TB
glad you finally got it working :)
Nov 10 '09 #6
Just wondering what the final outcome was, as i myself have the same javascript example...

Am having trouble getting the calculation to execute.

Cheers
Jul 26 '10 #7
Anyone help?
Aug 2 '10 #8

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

Similar topics

5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
1
by: Franko | last post by:
I get the following error. Please help c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,38): error CS1001: Identifier expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,52): error...
1
by: Franko | last post by:
I get the following error. Please help c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,38): error CS1001: Identifier expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,52): error...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
1
by: JOJO123 | last post by:
I got here in search of an answer to this Javascrpt question. I upgraded jave on XP Ie 7, acrobat 5.1 and suddenly can't open any pdf files on web sites using IE. I see u guys all say, this is a...
6
by: Lawrence Spector | last post by:
I ran into a problem using g++. Visual Studio 2005 never complained about this, but with g++ I ran into this error. I can't figure out if I've done something wrong or if this is a compiler bug. ...
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
2
by: thj | last post by:
Hi. I've got this form that I'm trying to validate: <form id="periodForm" action="" method="post"> <p> Periode: <input id="startDate" name="startDate" type="text" size="7" value="<%=...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.