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

Thread: warning message

  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    warning message

    Can someone tell me how to store three warning message in array.For instance,when click on a button, a warning appear and next time when clicking a another different message appear.Is it the same way as storing a username and password in an array, for a login purpose?
    Last edited by Lexium; 05-29-2012 at 05:43 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Here you are:-

    Code:
    <span id = "message" style="color:red"></span>
    
    <script type = "text/javascript">
    
    var warningmessage = [];
    warningmessage[0] = "This is the first warning message";
    warningmessage[1] = "This is the second warning message";
    warningmessage[2] = "This is the third warning message";
    var count = 0;
    function getmessage() {
    document.getElementById("message").innerHTML = warningmessage[count];
    count ++;
    if (count > 2) {count = 0}
    }
    
    </script>

    Quizmaster: What name is shared by rivers in Russia and in South Yorkshire?
    Contestant: The Tiber

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thx philip again.Always here to help me out with my problem.

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I do it like this..

    Code:
    <html>
    <head>
    <title></title>
    
    <script type = "text/javascript">
    
    var warningmessage = new Array();
    warningmessage[0] = "This is the first warning message";
    warningmessage[1] = "This is the second warning message";
    warningmessage[2] = "This is the third warning message";
    function getmessage(m) {
    for(i=0;i<m.length;i++){
    alert(m[i]);
    }
    }
    
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="Warning" onClick="getmessage(warningmessage);"/>
    </form>
    </body>
    </html><html>
    <head>
    <title></title>
    
    <script type = "text/javascript">
    
    var warningmessage = new Array();
    warningmessage[0] = "This is the first warning message";
    warningmessage[1] = "This is the second warning message";
    warningmessage[2] = "This is the third warning message";
    function getmessage(m) {
    for(i=0;i<m.length;i++){
    alert(m[i]);
    }
    }
    
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="Warning" onClick="getmessage(warningmessage);"/>
    </form>
    </body>
    </html>

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by Lexium View Post
    I do it like this..
    Well, only if you want all three warning mesages to appear when the button is clicked. You asked for "a warning to appear and next time when clicking a another different message to appear".

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Note that doing this in JavaScript means that each individual visitor cycles through the array independently. You'd need a server side script if you want to present the different messages to different people in sequence.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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