473,387 Members | 3,820 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,387 software developers and data experts.

having difficulty calling my functions (directly not threw events)

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
Nov 18 '08 #1
3 1152
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).
<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.
<P>
<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.
Nov 18 '08 #2
On Nov 18, 5:37*am, Henry <rcornf...@raindrop.co.ukwrote:
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.
<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).
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
Nov 19 '08 #3
On Nov 18, 9:55*pm, Andrew Falanga <af300...@gmail.comwrote:
On Nov 18, 5:37*am, Henry <rcornf...@raindrop.co.ukwrote:
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
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?

Nov 19 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matik | last post by:
Hi, I alredy tried to search this problem in last posts, but I couldn't find the answer. I try to access via Extended SP the method in a dll. I registered the dll as a ExSP, with a name of...
14
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild....
14
by: Gregory L. Hansen | last post by:
I can't seem to make a queue of objects, using the STL queue. I'm trying to make a little event manager, and I just want someplace to store events. The method definitions for EventManager have...
5
by: Zlatko Matić | last post by:
Hello. How can I call some functions on MSDE when working in .mdb ? Especially in-line functions which are similar to stored procedures. How can I use MSDE in-line functions as recordsource for...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
5
by: benc | last post by:
Hi Can some good soul help on this. I need to call jscript functions from C#. I have hosted a web control and displayed an html page successfully, but just can't find a way to call jscript...
8
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script>...
6
by: Radith Silva | last post by:
Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click If txtName.Text <> "" Then If txtUnits.Text <> "" Then If optOne.Checked Or...
12
by: Ron | last post by:
Greetings, I am trying to understand the rational for Raising Events instead of just calling a sub. Could someone explain the difference between the following 2 scenarios? Why would I want to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.