having difficulty calling my functions (directly not threw events)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Falanga

    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 displayFormElem ents(var form) {
    alert("actually inside the function now");
    document.write( "displayFormEle ments 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.eleme nts[0].value == "") {
    alert("form may not be null");
    }
    formId.submit() ;
    }

    </script>
    </head>
    <body>

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

    var form = document.getEle mentById("myFor m");
    document.write( "form contains " + form.length + " elements");
    displayFormElem ents(form);
    document.write( "after the call to displayFormElem ents");
    </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
  • Henry

    #2
    Re: having difficulty calling my functions (directly not threwevents)

    On Nov 18, 2:24 am, Andrew Falanga wrote:
    <snip>
    function displayFormElem ents(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.h tml" method="post">
    <input type=text name="text1"></input>
    <input type=button onClick="CheckF orNull()" 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.

    Comment

    • Andrew Falanga

      #3
      Re: having difficulty calling my functions (directly not threwevents)

      On Nov 18, 5:37 am, Henry <rcornf...@rain drop.co.ukwrote :
      On Nov 18, 2:24 am, Andrew Falanga wrote:
      <snip>functio n displayFormElem ents(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.h tml" method="post">
      <input type=text name="text1"></input>
      <input type=button onClick="CheckF orNull()" 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

      Comment

      • David Mark

        #4
        Re: having difficulty calling my functions (directly not threwevents)

        On Nov 18, 9:55 pm, Andrew Falanga <af300...@gmail .comwrote:
        On Nov 18, 5:37 am, Henry <rcornf...@rain drop.co.ukwrote :
        >
        On Nov 18, 2:24 am, Andrew Falanga wrote:
        <snip>functio n displayFormElem ents(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?

        Comment

        Working...