onSubmit, run a javascript, return true or false

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cssExp
    New Member
    • Jun 2007
    • 59

    onSubmit, run a javascript, return true or false

    hello,

    i want to check for errors on submitting a form, on encountering an error it runs a function and returns a false preventing form submit. I have implemented that.

    [CODE="javascrip t"]
    function eCheck()
    {
    var filePath = document.getEle mentsByName("fi leSelect");

    if (filePath == '')
    {
    errorPath();
    return false;
    }

    return true;
    }
    [/CODE]

    [CODE="HTML"]
    <form action="process .php" method="post" onSubmit="retur n eCheck();">
    [/CODE]

    When i do the above, it isn't going through the check or rather not running the function errorPath(); and returning the value as false.

    but when i do the following, errorPath(); works and form submit is called off.

    [CODE="HTML"]
    <form action="process .php" method="post" onSubmit="error Path(); return false;">
    [/CODE]

    but i want it to run the error check. Any ideas on way it's not working.

    Thanks in Advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you show the code for errorPath().

    Comment

    • cssExp
      New Member
      • Jun 2007
      • 59

      #3
      it only makes a div viable from hidden, nothing more is in it :)

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        Originally posted by cssExp
        [CODE="javascrip t"]
        var filePath = document.getEle mentsByName("fi leSelect");

        if (filePath == '') {
        // do something
        }
        [/CODE]
        hi ...

        filePath is a node-list the way you call it - so it will never be a single value ...

        use getElementById or loop through the list, or refer element with index=0 or something like that ... and compare the VALUE ;)

        kind regards

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by gits
          filePath is a node-list the way you call it - so it will never be a single value ...
          Oh, I missed that. I see what the OP tried to do. You should use getElementsByNa me for radio buttons and checkboxes to loop over them.

          Comment

          Working...