SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    UK
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile 2 form actions, 1 submit button

    Hi,

    I need a form to carryout 2 actions once the submit button is clicked.

    Below is some javascript that i'm playing with at the moment, my query is with the onclick parameter within the input tag. is that the correct way to call multiple functions??

    <input type=button name=test id=test onclick"DoFunction1();DoFunction2()">


    <SCRIPT LANGAUGE="Javascript">
    Function DoFunction1() {
    // Function 1
    }


    Function DoFunction2() {
    // Function 2
    }

    </SCRIPT>

    If anyone has a better way to do this or has done this before please let me know!

    Thanks,

    Allan

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amuller24
    is that the correct way to call multiple functions??
    If it works, then I wouldn't mess with it. If you wanted to tidy things up a little though, you could create a driver function:
    Code:
    <SCRIPT LANGUAGE="Javascript">
      Function DoAllFunctions(){
    	DoFunction1();
    	DoFunction2();
      }
     
      Function DoFunction1() {
    	// Function 1
      }
     
      Function DoFunction2() {
    	// Function 2
      }
    </SCRIPT>
     ...
    <input type=button name=test id=test onclick"DoAllFunctions()">
    but there seems little point.


    Andy

    P.S.
    Mind your "LANGAUGE"!
    From the English nation to a US location.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    UK
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Andy!

    One other question - Where do I insert the actions that each function should take?

    Would it be something like???

    Function DoFunction1() {
    // Function 1
    <form action="do something">
    }

    Can someone build a basic form around the script above so I can see how it can be implemented properly

    Thanks

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You said 'once the submit button is clicked'....so:


    <form......onsubmit="return(function1()&&function2())">
    ..........
    ..........
    <input type="submit">

    Add return true; to the end of each function.
    ::: certified wild guess :::


Bookmarks

Posting Permissions

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