What happens is that when I click on a button, a random string from the RandomString variable appears below the button. e.g I click on the button and it displays 'AAB' and then if I click on the button again it may display 'AAE' and etc.
The problem is that sometimes it displays 'undefined'. I don't wanit 'undefined' to appear but why does it sometimes display 'undefined' rather than a Random string.
Below is the code:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Create a Session</title>
<link rel="stylesheet" type="text/css" href="MyStyles.css">
<script type="text/javascript">
var randomStrings = [
"AAA",
"AAB",
"AAC",
"AAD",
"AAE",
];
function getSession() {
var randomDiv = document.getElementById("randomStrings");
randomIndex = Math.round((Math.random()*randomStrings.length-1));
newText = randomStrings[randomIndex];
randomDiv.innerHTML = newText;
}
</script>
</head>
<body>
<form action="create_session.php" method="post" name="sessionform">
<p><strong>1: </strong><input id="sessionBtn" type="button" value="Get Session ID" name="sessionid" onclick="getSession()" />
<div id="randomStrings"></div></p>
</form>
</body>
Thank You
This post has been edited by manleybruce: 16 November 2011 - 10:42 AM

New Topic/Question
Reply


MultiQuote






|