onclick doesn't work

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

    #1

    onclick doesn't work

    Hi,

    I've this piece of code which does not work at all.
    Can anyone point out my mistake?

    I've 2 buttons. History button will call verifyFields() function and
    lead to
    different page for processing. verifyFields() is working fine and so
    does the
    history() function.

    But,

    the other save button doesn't work. It's supposed to call the save()
    function and before executing the action, it will perform a check by
    executing
    checkFormFields (). However it does not execute these statements:
    --------------------------------------------------------------------
    document.ListFo rm.target="orig in";
    document.ListFo rm.action="List ByOrigin_update record.asp?acti on=check";
    --------------------------------------------------------------------
    The links above have been verified and it's working.




    <SCRIPT LANGUAGE="JavaS cript">
    <!--

    function checkFormFields ()
    {
    if(!isNumber(Li stForm.destinat ion.value))
    {
    alert("Destinat ion must not contain numbers at all.");
    ListForm.destin ation.focus();
    return false;
    }
    return true;
    }

    function history()
    {
    document.ListFo rm.target="adho c";
    document.ListFo rm.action="List ByOrigin.asp?ac tion=check";
    }

    function save()
    {
    if (checkFormField s() ) //doesn't execute these 2 lines.
    {
    document.ListFo rm.target="orig in";
    document.ListFo rm.action="List ByOrigin_update record.asp?acti on=check";
    return true;
    }
    }
    //-->
    </script>


    <form action="" method="post" name="ListForm" onSubmit="retur n
    verifyFields(); ">

    <input name="submit" type="submit" value="History"
    onClick="histor y()">

    <input name="submit" type="submit" id="submit" value="Save"
    onClick="return save();">

    </form>
  • Grant Wagner

    #2
    Re: onclick doesn't work

    kelvin wrote:
    [color=blue]
    > Hi,
    >
    > I've this piece of code which does not work at all.
    > Can anyone point out my mistake?
    >
    > I've 2 buttons. History button will call verifyFields() function and
    > lead to
    > different page for processing. verifyFields() is working fine and so
    > does the
    > history() function.
    >
    > But,
    >
    > the other save button doesn't work. It's supposed to call the save()
    > function and before executing the action, it will perform a check by
    > executing
    > checkFormFields (). However it does not execute these statements:
    > --------------------------------------------------------------------
    > document.ListFo rm.target="orig in";
    > document.ListFo rm.action="List ByOrigin_update record.asp?acti on=check";
    > --------------------------------------------------------------------
    > The links above have been verified and it's working.
    >
    > <SCRIPT LANGUAGE="JavaS cript">[/color]

    <script type="text/javascript">
    [color=blue]
    > <!--[/color]

    <!-- Not needed.
    [color=blue]
    > function checkFormFields ()
    > {
    > if(!isNumber(Li stForm.destinat ion.value))[/color]

    Where is "isNumber() " defined? It's not in the source you provided. As a result any
    attempt to call isNumber() will result in a syntax error.
    [color=blue]
    > {
    > alert("Destinat ion must not contain numbers at all.");
    > ListForm.destin ation.focus();
    > return false;
    > }
    > return true;
    > }
    >
    > function history()
    > {
    > document.ListFo rm.target="adho c";
    > document.ListFo rm.action="List ByOrigin.asp?ac tion=check";
    > }
    >
    > function save()
    > {
    > if (checkFormField s() ) //doesn't execute these 2 lines.[/color]

    As indicated above, checkFormFields () contains a call to an undefined function.
    [color=blue]
    > {
    > document.ListFo rm.target="orig in";
    > document.ListFo rm.action="List ByOrigin_update record.asp?acti on=check";
    > return true;
    > }[/color]

    You use "return save()" on the form, but save() does not always return a value, you should
    add "return false;" here. It may work without it, but it's a good habit to have functions
    that are supposed to return something always explicitly return something.
    [color=blue]
    > }
    > //-->[/color]

    //--> Not needed
    [color=blue]
    > </script>
    >
    > <form action="" method="post" name="ListForm" onSubmit="retur n
    > verifyFields(); ">
    >
    > <input name="submit" type="submit" value="History"
    > onClick="histor y()">
    >
    > <input name="submit" type="submit" id="submit" value="Save"
    > onClick="return save();">
    >
    > </form>[/color]

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    * http://devedge.netscape.com/library/...ce/frames.html
    * Internet Explorer DOM Reference available at:
    * http://msdn.microsoft.com/workshop/a...ence_entry.asp
    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • kelvin

      #3
      Re: onclick doesn't work

      hi Grant,

      I've done some changes and it works now.
      Thank you for your advise.

      Comment

      Working...