PDA

View Full Version : What's Wrong w/ My Code?!?!


Matt_Mikolaj
08-02-2005, 10:40 PM
Can anyone tell me why this code doesn't work or can anyone fix it? I want to have it that when the user types something in the textbox, a certain message comes up in the textarea! The options in the code are "Die" and "WEEEEEE". THX!


<form name="textbox">
<p align="center">
<textarea name="textarea" rows="30" cols="101"></textarea>
</p>
<input name="inputbox" type="text" size="130">
<button onclick="getinputinfo()">Click Here</button>
</form>

<script type="text/javascript">
var message = "Thou art in thy bedroom. Thy bed is not made.<br>Seen exits are north, east, and west.";
var inputbox = document.forms.textbox.inputbox.value;

function getinputinfo()
{
if(inputbox = "Die") message = "You are dead";
if(inputbox = "WEEEEEE") message = "I Don't Understand...";

document.forms.textbox.textarea.value = message;
}
</script>

_Aerospace_Eng_
08-02-2005, 10:52 PM
How is this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">

function getinputinfo() {
var inputbox = document.forms[0].inputbox1.value;
if(inputbox == "Die" || inputbox == "die") message = "You are dead";
else if(inputbox == "WEEEEEE" || inputbox == "weeeeee") message = "I Don't Understand...";
else message = "Thou art in thy bedroom. Thy bed is not made.\nSeen exits are north, east, and west.";
document.forms[0].textarea.value = message;
return false
}
</script>
</head>

<body onload="document.forms[0].inputbox1.focus()">
<form action="#" method="post" onsubmit="return getinputinfo()">
<p align="center">
<textarea name="textarea" rows="30" cols="101"></textarea>
</p>
<input name="inputbox1" type="text" size="130">
<input type="submit" value="Click Here">
</form>
</body>
</html>
It now works when you press enter in the text box or when you hit Click Here