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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Error: Object Expected" onClick function call

Status
Not open for further replies.

Seafury888

Programmer
Jun 3, 2003
11
CA
I'm making a web page that calculates the total of T-shirts purchased using a check() function, called by a button, in a form. Heres the important info.
1. The actual name of my form:
Code:
<form method=&quot;POST&quot; name=&quot;form&quot; action=&quot;--WEBBOT-SELF--&quot;>

2. The actual code for the button:
Code:
<input type=&quot;button&quot; value=&quot;Calculate Total&quot; name=&quot;B3&quot; onClick=&quot;check(form.form)&quot;>
//Note: my document's name is form.html, I have tried the syntax: check(this.form), check(form), check()...

3. The code for the check() function is:
Code:
<!--
	<script type=&quot;text/javascript&quot;>
	function check(form)
	{//check all the t-shirt text fields for non-numeric data
		for (i=13; i<form.length-2; i++)
		{
			if(isNaN(form.elements[i].value)
			{
				alert(&quot;You Must Enter a Number for &quot;+ form.elements[i].name);
				form.elements[i].value = &quot;&quot;;
				form.elements[i].focus();
				return;
			}
		}
		//all T-shirts contain numeric data
		//first T-shirt text box is entity #13, calculation adds up entities 13-16, and puts them in the &quot;Total&quot; entity.
                var total = 0;
		for(i=13; i<form.length-2; i++)
			total = (total + parseFloat(form.elements[i].value))*18.00;
		form.Total.value = total + 5.00;	
	
-->

When I enter values in the text fields and click the button to calculate the total, I get the error &quot;Object Expected&quot; on the line containing the button code.
Any help with this problem is greatly appreciated.

Ian
 
The problem is probably because you named the form 'form'. Name it something else and see if it works. Also, the correct syntax for the input line is this:

<input type=&quot;button&quot; value=&quot;Calculate Total&quot; name=&quot;B3&quot; onClick=&quot;check(this.form)&quot;>

If it still doesn't work, post your entire source.
 
You can try this:
<input type=&quot;button&quot; value=&quot;Calculate Total&quot; name=&quot;B3&quot; onClick=&quot;javascript:check(document.form)&quot;>
 
Ok, I've changed the name of the form to form1 and made the appropriate adjustments (I think) and I'm getting the same error, so ....Heres then entire source for that page.

If you see a [bold] or
Code:
 tag ignore it, I was trying to bold the important lines of code for this post but couldn't get it to work right >P.
[code]
<html>

<head>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-us&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<title>PORCUPINE HILLS</title>
<!--
	<script type=&quot;text/javascript&quot;>
	function check(form1)
	{//check all the t-shirt text fields for non-numeric data
		for (i=13; i<form1.length-2; i++)
		{
			if(isNaN(form1.elements[i].value)
			{
				alert(&quot;You Must Enter a Number for &quot;+ form1.elements[i].name);
				form1.elements[i].value = &quot;&quot;;
				form1.elements[i].focus();
				return;
			}
		}
		//all T-shirts contain numeric data
		var total = 0;
		for(i=13; i<form1.length-2; i++)
			total = (total + parseFloat(form1.elements[i].value))*18.00;
		form1.Total.value = total + 5.00;	
	</script>
-->
</head>

<body>

<h1 align=&quot;center&quot;><font face=&quot;Vineta BT&quot;>PORCUPINE HILLS</font></h1>
<h1 align=&quot;center&quot;><font face=&quot;Vineta BT&quot;>CLASSIC CRUISERS</font></h1>
<div align=&quot;center&quot;>
  <center>
  <table border=&quot;1&quot; width=&quot;100%&quot; height=&quot;62&quot;>
    <tr>
      <td width=&quot;100%&quot; height=&quot;56&quot;>
        <h2 align=&quot;center&quot;><b><font face=&quot;Times New Roman&quot;>11TH ANNUAL SHOW 'N'
        SHINE REGISTRATION FORM</font></b></h2>
        <h2 align=&quot;center&quot;><b><font face=&quot;Times New Roman&quot;>Saturday, August 16,
        2003 1:00 - 4:00 p.m.</font></b></h2>
      </td>
    </tr>
  </table>
  </center>
</div>
[bold]<form method=&quot;POST&quot; name=&quot;form1&quot; action=&quot;--WEBBOT-SELF--&quot;>[/bold][code]
  <!--webbot bot=&quot;SaveResults&quot; U-File=&quot;A:\_private\form_results.txt&quot;
  S-Format=&quot;TEXT/CSV&quot; S-Label-Fields=&quot;TRUE&quot; -->
  <p>First Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=&quot;text&quot; name=&quot;T1&quot; size=&quot;20&quot;>&nbsp;&nbsp;
  </p>
  <p>Last Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=&quot;text&quot; name=&quot;T2&quot; size=&quot;20&quot;>
  </p>
  <p>Phone:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input type=&quot;text&quot; name=&quot;T3&quot; size=&quot;20&quot;> </p>
  <p>Address:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=&quot;text&quot; name=&quot;T4&quot; size=&quot;110&quot;></p>
  <p>City:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input type=&quot;text&quot; name=&quot;T5&quot; size=&quot;20&quot;> </p>
  <p>Province/State: <input type=&quot;text&quot; name=&quot;T6&quot; size=&quot;20&quot;> </p>
  <p>PostalCode/Zip:<input type=&quot;text&quot; name=&quot;T7&quot; size=&quot;20&quot;></p>
  <p>Club:<input type=&quot;text&quot; name=&quot;T8&quot; size=&quot;54&quot;></p>
  <p align=&quot;center&quot;><b>Vehicle Information</b></p>
  <p align=&quot;left&quot;>Mileage:<input type=&quot;text&quot; name=&quot;T9&quot; size=&quot;20&quot;> Year:<input type=&quot;text&quot; name=&quot;T10&quot; size=&quot;20&quot;>
  Make:<input type=&quot;text&quot; name=&quot;T11&quot; size=&quot;20&quot;> Model:<input type=&quot;text&quot; name=&quot;T12&quot; size=&quot;20&quot;></p>
  <p align=&quot;center&quot;><b>PLEASE MAKE CHEQUES PAYABLE TO &quot;PORCUPINE HILLS CLASSIC
  CRUISERS&quot;,<BR>BOX 2586 CLARESHOLM, ALBERTA T0L 0T0</b>
  </p>
  <p align=&quot;left&quot;><b>Registration: $5.00&nbsp;(Canadian Funds) <br></b>
[bold]<b>T-Shirts: S<input type=&quot;text&quot; name=&quot;Small&quot; size=&quot;7&quot;>M<input type=&quot;text&quot; name=&quot;Medium&quot; size=&quot;7&quot;>L<input type=&quot;text&quot; name=&quot;Large&quot; size=&quot;7&quot;>XL<input type=&quot;text&quot; name=&quot;XLarge&quot; size=&quot;7&quot;>x
$18.00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=&quot;button&quot; value=&quot;Calculate Total&quot; name=&quot;B3&quot; onClick=&quot;check(this.form1)&quot;> $<input type=&quot;text&quot; name=&quot;Total&quot; size=&quot;11&quot;></b>[/bold]
Code:
  </p>
  <p><input type=&quot;submit&quot; value=&quot;Send&quot; name=&quot;B1&quot;><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></p>
</form>

</body>

</html>


Many thanks once again for your help with this.

Ian
P.S. I'm using Microsoft Front Page.
 
Prepare to kick thyself...

The <SCRIPT> tags go OUTSIDE the <!-- and -->!

You will find you also need a close curly brace ( } ) on the check function and a second close parenthesis ( ) ) on the parameter list of the if-statement in the check function.

'hope that helps!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top