...

View Full Version : warning message



Lexium
05-29-2012, 05:38 PM
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?

Philip M
05-29-2012, 06:02 PM
Here you are:-


<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

Lexium
05-29-2012, 06:13 PM
thx philip again.Always here to help me out with my problem.:)

Lexium
05-29-2012, 06:36 PM
I do it like this..:)



<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>

Philip M
05-29-2012, 07:28 PM
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".

felgall
05-29-2012, 08:04 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum