www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: more alert boxes on one page...

  1. #16
    Join Date
    Jan 2009
    Posts
    30

    ...

    ...to pass the string in the parameters of the function... unfortunately just dont get it ...

  2. #17
    Join Date
    Mar 2007
    Posts
    946
    PHP Code:
    <script type="text/javascript">
    function 
    myfunction(mystring)
    {
    alert(mystring);
    }
    </script>
    <form>
    <input type="button" onclick="myfunction('string1')" value="a)">
    </form>

    <form>
    <input type="button" onclick="myfunction('string2')" value="b)">
    </form>

    <form><input type="button" onclick="myfunction('string3')" value="c)">
    </form> 
    If you look there is only one function declaration, but there are three calls to the same function passing a string value (string1, string2, string3).

  3. #18
    Join Date
    Sep 2008
    Location
    On the Interweb
    Posts
    125
    Skywalker's solution will work very well for you. However, as I noted in my original suggestion, your problem lies in the fact that the way you set it up, you keep declaring your function as "myfunction" each time, yet you are trying to get it to return 3 different things - the function needs to be called something different if you use it multiple times. - note the red numbers in the amended code below

    Quote Originally Posted by marija View Post
    <script type="text/javascript">
    function myfunction(){alert("A dog");}
    </script>
    <form><input type="button" onclick="myfunction()" value="a)"></form>
    <br>
    <br>
    <script type="text/javascript">
    function myfunction1(){alert("A cat ");}
    </script>
    <form><input type="button" onclick="myfunction1()" value="b)"></form>
    <script type="text/javascript">
    function myfunction2(){alert("A mouse");}
    </script>
    <form><input type="button" onclick="myfunction2()" value="C"></form>

    You don't HAVE to call them myfunction1 and myfunction2, I simply named them as an example. They could just as easily be myfunctioncat, myfunctionmouse, myfunctiondog or myfunctionhugo, myfunctiongeorge, myfunction382, or whatever.

    So, you can change your code as suggested by Skywalker, or if you leave your code as typed, just make sure each function is named differently.
    Last edited by Mayday; 01-28-2009 at 01:20 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles