471,316 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Someone - **please, please, please** help :-( .js problem

Hello,

I have an HTML page that I am trying to import 2 .js file (I created)
into. These files are: row_functions.js and data_check_functions.js.
Whenever I bring the contents of the files into this HTML file, all is
OK but whenever the functions are separated (as it is now), when I run
the page, I get the following error:

Line 73, object expected.

Line 73 below is:

<INPUT onClick="if (FTry2(PrepObj('FrmX'))) {
addRowToTable('FDependents', form.FDependSocialSecurityNumber.value,
form.FDependLastName.value,
form.FDependFirstName.value, form.FDependMiddleInitial.value,
form.FDependDateOfBirth.value, form.FDependState.value,
form.FDependZipCode.value, form.FDependPhoneNumber.value,
form.FDependAmountPaid.value, form.FDependRelationship.value); } "
type=button value=" Add " name="Add">

In other words, there seems to be something wrong with the "onClick"
event. It does not seem to recognize the functions I have in the other
..js files. It does not get into the "FTry2" or the "PrepObj" functions
(I had placed an "alert" there at the entry point of the functions and
they never fired.

Someone please help :-( What am I doing wrong?

----------------------- HTML PAGE LISTED BELOW ------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
</HEAD>
<script language="javascript" TYPE="application/x-javascript"
src="file:///C|Documents and Settings\Desktop\BASE
PAGE\row_functions.js" >
<script language="javascript" TYPE="application/x-javascript"
src="file:///C|Documents and Settings\Desktop\BASE
PAGE\data_check_functions.js" >

<SCRIPT language=JavaScript type="text/javascript">
function PrepObj(Frm) {
alert("got in this shit");
// So written to allow display by ShowFF()
with (document.forms[Frm]) return { Fawm:Frm, A:[
// {F:"Field" W:"What" H:"How" ?R:RegExp ?V:ValFn ?P{Params}},
{F:"FDependSocialSecurityNumber", W:"Social Security Number", H:"be
in ###-##-#### format ", V:RegCheckSocialOK},
{F:"FDependLastName", W:"Last Name", H:"non-blank", V:FmlyOK},
{F:"FDependFirstName", W:"First Name", H:"non-blank", V:FmlyOK},
{F:"FDependMiddleInitial", W:"Middle Initial", H:"non-blank",
V:FmlyOK},
{F:"FDependDateOfBirth", W:"Date of Birth", H:"in valid format
MM-DD-YYYY", V:RegCheckDateOK, V:DateOK},
{F:"FDependState", W:"State", H:"non-blank", V:FmlyOK},
{F:"FDependZipCode", W:"Zip Code", H:" ", V:RegCheckZipOK},
{F:"FDependPhoneNumber", W:"Phone Number", H:" in XXX-XXX-XXXX form
", V:RegCheckUSPhoneOK},
{F:"FDependAmountPaid", W:"Amount Paid", H:"in dollars and cents ",
V:RegCheckUSDollarsOK},
{F:"FDependRelationship", W:"Relationship", H:"non-blank",
V:FmlyOK}
] } }

function loadData(){
addRowToTable(1,2,3,4,5,6,7,8,9,10);
}
</SCRIPT>
<BODY>
<FORM name=FrmX >
<div ID="errmesg"> </div>
Social Security Number <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=11 name=FDependSocialSecurityNumber>
<br>Last Name<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=35 name=FDependLastName>
<br>First Name<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=35 name=FDependFirstName>
<br>Middile Initial<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=1 name=FDependMiddleInitial>
<br>Date Of Birth<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=12 name=FDependDateOfBirth>
<br>State<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<S ELECT size=1 "
style="width:300px" name=FDependState>
<OPTION value=TX >TX</OPTION>
<OPTION value=CA>CA</OPTION>
<OPTION value=FL>FL</OPTION>
<OPTION value=NY>NY</OPTION>
</SELECT>
<br>Zip Code<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=5 name=FDependZipCode>
<br>Phone Number<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=12 name=FDependPhoneNumber>
<br>Amount Paid<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=8 name=FDependAmountPaid>
<br>Relationship<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<SELECT size=1 style="width:300px" name=FDependRelationship>
<OPTION value=1 selected>1- MOTHER</OPTION>
<OPTION value=2>2- FATHER</OPTION>
<OPTION value=3>3- SISTER</OPTION>
<OPTION value=4>4- BROTHER</OPTION>
<OPTION value=5>5- GRANDMOTHER</OPTION>
<OPTION value=6>6- GRANDFATHER</OPTION>
</SELECT>
<P>

<TABLE width=388><TBODY><TR>
<TD width=113>
<INPUT onClick="if (FTry2(PrepObj('FrmX'))) {
addRowToTable('FDependents', form.FDependSocialSecurityNumber.value,
form.FDependLastName.value,
form.FDependFirstName.value, form.FDependMiddleInitial.value,
form.FDependDateOfBirth.value, form.FDependState.value,
form.FDependZipCode.value, form.FDependPhoneNumber.value,
form.FDependAmountPaid.value, form.FDependRelationship.value); } "
type=button value=" Add " name="Add">
</TD>
<TD width=154>
<INPUT onclick=removeRowFromTable('FDependents'); type=button
value=Remove name=Remove>
</TD><TD width=154>
<INPUT onclick=openInNewWindow(this.form); type=submit value=Continue
name=Continue>
</TD>
</TR>
</TBODY></TABLE>
</FORM>
</P>
<FORM name=FrmTabX action="#">
<TABLE id="FDependents" class=table cellSpacing=0 cellPadding=0
width="100%" align=left border=1>
<TBODY>
<TR>
<TD vAlign=top bgColor=darkgreen><FONT color=#006633><FONT
color=#ffffff>Choice</FONT> </FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Social Sec
No.</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT
color=#ffffff>LastName</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>First
Name</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Middle
</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Date of
Birth</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>State </FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Zip
Code</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Phone
Number</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Amount Pd.
</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT
color=#ffffff>Relationship</FONT></TD></TR>
<TR>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
</TR>
</TBODY></TABLE></P>
</FORM>
</BODY>
</HTML>

Jul 23 '05 #1
11 1762
milkyway wrote:
Hello,

I have an HTML page that I am trying to import 2 .js file (I created)
into. These files are: row_functions.js and data_check_functions.js.
Whenever I bring the contents of the files into this HTML file, all is
OK but whenever the functions are separated (as it is now), when I run
the page, I get the following error:

Line 73, object expected.

Line 73 below is:

<INPUT onClick="if (FTry2(PrepObj('FrmX'))) {
addRowToTable('FDependents', form.FDependSocialSecurityNumber.value,


where is 'addRowToTable' defined?

Reduce your problem to the smallest amount of code to still show it
(say one form input and minimal HTML) and re-post - at least get rid of
all the &nbsp; - use padding or margin or some other layout technique.

Try changing references such as:

form.FDependSocialSecurityNumber.value

to:

forms.FrmX.FDependSocialSecurityNumber.value

Also, all your attribute values should be quoted, not just some of
them. And ditch "language='javascript' " - it's depreciated and
replaced by type="text/javascript".

--
Fred
Jul 23 '05 #2
On 16 Jan 2005 05:01:36 -0800, in comp.lang.javascript "milkyway"
<d0******@hotmail.com> wrote:
| Hello,
|
| I have an HTML page that I am trying to import 2 .js file (I created)
| into. These files are: row_functions.js and data_check_functions.js.
| Whenever I bring the contents of the files into this HTML file, all is
| OK but whenever the functions are separated (as it is now), when I run
| the page, I get the following error:
|
| Line 73, object expected.
|
| Line 73 below is:
|
| <INPUT onClick="if (FTry2(PrepObj('FrmX'))) {
| addRowToTable('FDependents', form.FDependSocialSecurityNumber.value,
| form.FDependLastName.value,
| form.FDependFirstName.value, form.FDependMiddleInitial.value,
| form.FDependDateOfBirth.value, form.FDependState.value,
| form.FDependZipCode.value, form.FDependPhoneNumber.value,
| form.FDependAmountPaid.value, form.FDependRelationship.value); } "
| type=button value=" Add " name="Add">
|
| In other words, there seems to be something wrong with the "onClick"
| event. It does not seem to recognize the functions I have in the other
| .js files. It does not get into the "FTry2" or the "PrepObj" functions
| (I had placed an "alert" there at the entry point of the functions and
| they never fired.
|
| Someone please help :-( What am I doing wrong?
|
| ----------------------- HTML PAGE LISTED BELOW ------------------
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
| <HTML>
| <HEAD>
| <META http-equiv=Content-Type content="text/html;
| charset=windows-1252">
| </HEAD>
| <script language="javascript" TYPE="application/x-javascript"
| src="file:///C|Documents and Settings\Desktop\BASE
| PAGE\row_functions.js" >
| <script language="javascript" TYPE="application/x-javascript"
| src="file:///C|Documents and Settings\Desktop\BASE
| PAGE\data_check_functions.js" >


Your script files are pointing to your hard drive. You should make the
links point to the folder within your website. For example the script
files are in a folder called scripts, your <script> tags would look
like:
<script language="javascript" TYPE="application/x-javascript"
src="folder/row_functions.js" >
<script language="javascript" TYPE="application/x-javascript"
src="folder/data_check_functions.js" >

Script tags etc should normally be placed between the <head></head>
tags, the browser could be ignoring them in your code.

The Type attribute should be type="text/javascript" but don't quote me
on that.

---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #3
Fred Oz wrote:
<snip>
Try changing references such as:

form.FDependSocialSecurityNumber.value

to:

forms.FrmX.FDependSocialSecurityNumber.value
The first (left most) item in these property accessors is (in ECMAScript
production rule terms) an Identifier and will be resolved against the
scope chain of the (internally generated, for code defined in an
intrinsic event attribute strings) event handling function (as per ECMA
272 (3rd edition) Section 10.1.4 "Scope Chain and Identifier
Resolution").

As a result, error-free resolution of either of those property accessors
requires that the left most Identifier correspond with a named property
of one of the objects on the function's scope chain that holds a
reference to an object. When closures are not being employed, the normal
scope chain of an executing javascript function will contain the
Activation/Variable object (holding references to the function's formal
parameters, named inner function declarations and local variables) of
the individual execution context followed by the global/window object.
The global/window object would not normally be expected to have
properties named "form" or "forms" and so both of those property
accessors will fail.

In practice some browsers (including the more common ones) add a custom
scope chain to the event handling functions that they internally
generate from intrinsic event attribute string defined code. Those
custom scope chains do include a number of objects from the DOM,
depending on the browser in question. If the browser has added the INPUT
element on which the attribute is specified to the scope chain, then
"form" will resolve as a reference to the W3C HTML DOM specified (and
seemingly universally supported) - form - property of the INPUT element
(or, more precisely the HTMLInputElement interface). And when the -
document - element is added to the scope chain "forms" will be resolved
as the W3C HTML DOM specified - forms - collection of the HTMLDocument
interface (universally implemented in HTML DOMs, but missing form some
older XHTML DOM implementations).

Experimentation has suggested that all of the browsers that do provide a
custom scope chain for event handling functions internally generated
from intrinsic event attribute strings will place the element on which
the attribute appears on that scope chain. However, the placing of a
reference to the - document - on that scope chain is less commonly
implemented. Thus the proposed switch from the original property
accessor to the proposed alternative will sacrifice some cross-browser
compatibility for no particularly good reason.

On the other hand, the creating of custom scope chains for internally
generated event handling functions is not defined in (or even suggested
by) any published specification/recommendation, so it is surprising that
where they are created they differ in behaviour. And it is also not
surprising that some (otherwise reasonably standards compliant) browsers
do not implement such a mechanism at all (leaving their internally
generated event handling functions with scope chains that satisfy ECMA
262 but go no further). For these browsers both property accessor
formulations will error, rather than resolving to useful values.

To maximise the cross-browser compatibility the code defined in the
string values of intrinsic event attributes that code should be written
as if it was the function body definition of any top level
ECMAScirpt/javascript function assigned to an event handling property of
a DOM element. No reliance on the inconstantly implemented custom scope
chains should be made. Instead property accessors should be capable of
being sucessfully resolved in a normal ECMAScirpt execution context.
Thus:-

forms.FrmX.FDependSocialSecurityNumber.value

- would be better specified as:-

document.forms.FrmX.FDependSocialSecurityNumber.va lue

-(because - document - can be expected to be a property of the
global/window object and so will be on the scope chain of any and all
ECMAScript functions). And:-

form.FDependSocialSecurityNumber.value

- would be better as:-

this.form.FDependSocialSecurityNumber.value

- because the - this - keyword refers to the object with which the
function is executed as a method (the INPUT element in the case of an
event handler associated with that element).

The latter property accessor probably being the best option as it allows
referencing via the form without any interest in the name/ID of the
form. Allowing the form to be treated anonymously and so making the code
more portable.

Ideally both property accessors would reference the individual form
controls via the form's - elements - collection in order to fully
conform with the W3C DOM specification, rather than relying on the
'shortcut' of referring to those controls as named properties of the
form element itself (even though no scriptable browsers that understand
forms are known that do not implement the 'shortcut').
Also, all your attribute values should be quoted, not
just some of them.

<snip>

In HTML (as opposed to XHTML) 'should' is too strong a term. Quoting all
attribute strings is often suggested as good practice but rules exist
that define when attribute strings must be quoted, and when it is not
necessary. The advantage of quoting all attribute strings is that it can
never be wrong and makes it unnecessary to remember the rules about when
it must be done.

Follow-ups set to comp.lang.javascript.

Richard.
Jul 23 '05 #4
Hi Fred,

Fred Oz wrote:
milkyway wrote:

Line 73 below is:

<INPUT onClick="if (FTry2(PrepObj('FrmX'))) {
addRowToTable('FDependents',
form.FDependSocialSecurityNumber.value,
where is 'addRowToTable' defined? The function "addRowToTable" is in the .js file "row_functions.js". I
thought that by referencing this file in my HTML file, that it would be
imported here and work - am I wrong?
Reduce your problem to the smallest amount of code to still show it
(say one form input and minimal HTML) and re-post - at least get rid of all the &nbsp; - use padding or margin or some other layout technique.
I have paired it down to the following. I still get the error. But
here, no .js files are used and I still get the same error on:

<INPUT onClick="working();" type="button" value=" Add "
name="Add">

I don't see what is wrong .... :-(

--------- PAIRED DOWN CODE BELOW ----------------------------

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
</HEAD>

<SCRIPT language="JavaScript" TYPE="application/x-javascript">

function working()
{
alert("got in here");
}

</SCRIPT>
<BODY>
<FORM name=FrmX >
<TABLE width=388>
<TBODY>
<TR>
<TD width=113>
<INPUT onClick="working();" type="button" value=" Add "
name="Add">
</TD>
</TR>
</TBODY>
</TABLE>
</FORM>

<FORM name=FrmTabX action="#">
</FORM>
</BODY>
</HTML>
Try changing references such as:

form.FDependSocialSecurityNumber.value

to:

forms.FrmX.FDependSocialSecurityNumber.value

Also, all your attribute values should be quoted, not just some of
them. And ditch "language='javascript' " - it's depreciated and
replaced by type="text/javascript".


I have made the replacements but I don't think the processing gets that
far to access these values. I have paired the code down though - please
see above.

Kindest Regards.

Jul 23 '05 #5
Hi Jeff,

Jeff North wrote:
On 16 Jan 2005 05:01:36 -0800, in comp.lang.javascript "milkyway"
<d0******@hotmail.com> wrote:
Your script files are pointing to your hard drive. You should make the links point to the folder within your website. For example the script
files are in a folder called scripts, your <script> tags would look
like:
<script language="javascript" TYPE="application/x-javascript"
src="folder/row_functions.js" >
<script language="javascript" TYPE="application/x-javascript"
src="folder/data_check_functions.js" >


My code is currently not on a website. I am doing some tests without
one. Is there a way to use the .js files even though they are located
on your hard drive? If so, how?

Kindest Regards.

Jul 23 '05 #6
Hello all,

Thank you for your help :-) I think the reason for the problem has
changed. Basically, if someone can tell me how to include a .js file
that is on the hard drive, then all will be OK --- I think ...
How does one do this?

TIA

Jul 23 '05 #7
milkyway wrote:
Hello all,

Thank you for your help :-) I think the reason for the problem has
changed. Basically, if someone can tell me how to include a .js file
that is on the hard drive, then all will be OK --- I think ...
How does one do this?


This should not present a problem at all.
Mick
Jul 23 '05 #8
milkyway wrote:
[...]
I have paired it down to the following. I still get the error. But
here, no .js files are used and I still get the same error on:

<INPUT onClick="working();" type="button" value=" Add "
name="Add">

I don't see what is wrong .... :-(
I don't get any errors, however:

--------- PAIRED DOWN CODE BELOW ----------------------------

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
You are missing the opening "<", but I'll assume that is just an error
in copy/paste.

[...] <SCRIPT language="JavaScript" TYPE="application/x-javascript">
Language is depreciated, the correct type is:

<script type="text/javascript">
<FORM name=FrmX >
Quote attributes:

... name="FrmX">
<TABLE width=388>
And here:

... width="388">

et cetera

[...] <FORM name=FrmTabX action="#">
If you want no action, use:

<FORM name="FrmTabX" action="">

I have made the replacements but I don't think the processing gets that
far to access these values. I have paired the code down though - please
see above.


The only thing that might stop your code from working is the incorrect
type, but even that was tollerated by Firefox.

--
Fred
Jul 23 '05 #9
milkyway wrote:
Hello all,

Thank you for your help :-) I think the reason for the problem has
changed. Basically, if someone can tell me how to include a .js file
that is on the hard drive, then all will be OK --- I think ...
How does one do this?

TIA


Your original file path was:

<script language="javascript" TYPE="application/x-javascript"
src="file:///C|Documents and Settings\Desktop\BASE
PAGE\row_functions.js" >

The use of pipe "|" is illegal in a file name/path.

All paths should use forward slash "/", not backward "\".

For development, put your .js files in the same directory as your web
page or in a sub-directory and reference with a relative path.

e.g. create a sub-directory where your HTML is called "scripts", then
reference your script file as:

<script type="text/javascript"
src="scripts/row_functions.js">
</script>

--
Rob
Jul 23 '05 #10
On Sun, 16 Jan 2005 22:41:02 GMT, Fred Oz <Oz****@iinet.net.auau> wrote:
<FORM name=FrmX >


Quote attributes:

... name="FrmX">
<TABLE width=388>


And here:

... width="388">


In both those cases the quotation marks are optional.

--
Stephen Poley

http://www.xs4all.nl/~sbpoley/webmatters/
Jul 23 '05 #11
Followups to ciwah.

Fred Oz wrote:
If you want no action, use:

<FORM name="FrmTabX" action="">


That doesn't mean 'no action'. When that form is submitted,
any form data should be sent to the resource identified by
the base URI of the current document.

I wouldn't use an empty action, however, even though it
conforms with a loose interpretation of the spec.* Are
there any browsers which adhere to the URI RFC on this?
RFC2396 says that

| if the URI reference occurs in a context that is always
| intended to result in a new request, as in the case of
| HTML's FORM element, then an empty URI reference
| represents the base URI of the current document and should
| be replaced by that URI when transformed into a request.

http://www.ietf.org/rfc/rfc2396.txt

When deciding what URI to submit form data to, some browsers
ignore base URIs specified by BASE elements and incorrectly
employ the URI of the current document.
* Specifically, taking 'URI' to mean 'URI reference'.

--
Jock
Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Nafai | last post: by
7 posts views Thread by rn5a | last post: by
40 posts views Thread by aslamhenry | last post: by

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.