having difficulty calling my functions (directly not threw events)

A

Andrew Falanga

Hi,

Here's what I've got:

<html>
<head>
<script type="text/javascript">
function foo() {
document.write("foo");
alert("foo");
}

function displayFormElements(var form) {
alert("actually inside the function now");
document.write("displayFormElements called");
var length = form.length;
for(var i = 0; i < length; i++) {
document.write("element " + i + " is " + form.type);
}
}
function CheckForNull() {
var formId=document.getElementById("myForm");
if(formId.elements[0].value == "") {
alert("form may not be null");
}
formId.submit();
}

</script>
</head>
<body>

Form test
<form id="myForm" action="index.html" method="post">
<input type=text name="text1"></input>
<input type=button onClick="CheckForNull()" value="submit" />
<P>
<script language="javascript" type="text/javascript">
foo();
document.write("body script section");

var form = document.getElementById("myForm");
document.write("form contains " + form.length + " elements");
displayFormElements(form);
document.write("after the call to displayFormElements");
</script>
</form>
</body>
</html>

This is my test bed, so to speak. I want to understand what it is I'm
looking at (in the forms) so I wanted to see the data. So, in a
different page I tried to do it and nothing happens in the script tag
in the body section. What am I doing wrong?

Andy
 
H

Henry

On Nov 18, 2:24 am, Andrew Falanga wrote:
function displayFormElements(var form) {
<snip> ^^^

That - var - in the function's parameters list is a fatal syntax error
(and any browser's javascript error reporting mechanism would have
reported it, if you had bothered to look).
<form id="myForm" action="index.html" method="post">
<input type=text name="text1"></input>
<input type=button onClick="CheckForNull()" value="submit" />

This document is not XHTML (and could not be if you are using -
document.wirte - as XHTML DOMs mostly don't support its use) so the
use of XHTML style mark-up is inappropriate. But maybe it is worse
than inappropriate as the error correcting that will be applied to get
the above noise back to something that makes sense as HTML is quite
likely to result in differing DOM structures in different browsers
(error correction not being something that can be standardised).

For example, IE 6 thinks that the FORM element in the above document
has 6 child nodes, but change:-

<input type=text name="text1"></input>

- to the correct HTML of:-

<input type=text name="text1">

- and then IE only sees 5 child nodes of the FORM element.
<snip>

And if you are going to use XHTML style mark-up in your HTML documents
it really does not make any sense to mix it with HTML mark-up. The
closing tag of a P element may be optional in HTML (implied by
context) but in XHTML its handling must be explicit.
 
A

Andrew Falanga

On Nov 18, 2:24 am, Andrew Falanga wrote:
<snip>> function displayFormElements(var form) {

<snip>                         ^^^

That - var - in the function's parameters list is a fatal syntax error
(and any browser's javascript error reporting mechanism would have
reported it, if you had bothered to look).

And how would this error reporting mechanism manifest itself? I'm
using Firefox 3.0.(something) on FreeBSD and all that happened was the
page simply didn't do anything with the functions. However, your
response here did clue me into my issue. Thanks. Some hold overs
from writing C and C++. I'm used to having to declare the function
arg types in the arg list.
This document is not XHTML (and could not be if you are using -
document.wirte - as XHTML DOMs mostly don't support its use) so the
use of XHTML style mark-up is inappropriate. But maybe it is worse
than inappropriate as the error correcting that will be applied to get
the above noise back to something that makes sense as HTML is quite
likely to result in differing DOM structures in different browsers
(error correction not being something that can be standardised).

You're right, it's not. Forgive the ignorance but I'm a neophyte to
javascript and not much more than that to html.

Andy
 
D

David Mark

And how would this error reporting mechanism manifest itself?  I'm

In the error console for one. Tools | Error Console.
using Firefox 3.0.(something) on FreeBSD and all that happened was the
page simply didn't do anything with the functions.
[snip]


You're right, it's not.  Forgive the ignorance but I'm a neophyte to
javascript and not much more than that to html.

Have you considered writing a library?
 
A

Andrew Falanga

In the error console for one.  Tools | Error Console.

For all the time that I've used Firefox I've not know this was there.
Thanks.
using Firefox 3.0.(something) on FreeBSD and all that happened was the
page simply didn't do anything with the functions.
[snip]



You're right, it's not.  Forgive the ignorance but I'm a neophyte to
javascript and not much more than that to html.

Have you considered writing a library?

Ultimately, that's what this is aimed at. I'm just learning
javascript at this point to make it happen.

Andy
 
D

David Mark

In the error console for one.  Tools | Error Console.

For all the time that I've used Firefox I've not know this was there.
Thanks.
using Firefox 3.0.(something) on FreeBSD and all that happened was the
page simply didn't do anything with the functions.
You're right, it's not.  Forgive the ignorance but I'm a neophyte to
javascript and not much more than that to html.
Have you considered writing a library?

Ultimately, that's what this is aimed at.  I'm just learning
javascript at this point to make it happen.

I knew it. That is the first aspiration of every frustrated
neophyte. Then you learn better, hopefully before you have spread
your creation all over the Web.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top