Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Running Multiple Functions

    Hi All,

    pls I need help on how to run multiple JavaScript, I tried my bellow code, it actually runs(validate) but as soon as I click the Okay button of the Dialog Box it submit the form.

    So what I really want is how to use If Construct for testing Functions, see bellow code;

    <script language = "Javascript">
    function Submittest()
    {
    Submit();

    ValidateForm();

    }

    </script>

    I want to test Submit() [Using IF statement.....] if it returns false, the Script should not allow me to submit the form
    Abdul

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Uuuuh?

    I want to test Submit() [Using IF statement.....] if it returns false, the Script should not allow me to submit the form
    The validation script (which you did not post) should
    not allow the form to submit() unless the form validates.

    Besides, in your Submittest() function.
    You are submitting the form and then validating.

    This:

    function Submittest()
    {
    Submit();
    ValidateForm();
    }
    </script>

    Should at least be this:

    function Submittest()
    {
    ValidateForm();
    Submit();

    }
    </script>

    ....Willy

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    the smarter thing to do would be use the form tag attribute

    <form name="theForm" onSubmit="return Validate()">


    in your Validate function you would need to return true or false

  • #4
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank guys,

    both Submit() and ValidateForm() are JavaScript that validate different textfields.

    I just want to be able to run these two different JavaScript together, because I ran one other JavaScript with <form ... tag and am trying to run this Submittest() through the onClick event.

    Thanks
    Abdul

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Simply do an inclusive boolean check:

    <form ... onsubmit="return SubmitTest(this);">

    Code:
    function SubmitTest(form){
        return (Submit(form) && ValidateForm(form))
    }
    For it to submit, both Submit and ValidateForm need to evaluate to true.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi liorean,

    thanks alot, it work fine.

    Abd
    Abdul


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •