...

View Full Version : Need help clearing a textbox



Marlin
07-11-2006, 09:30 AM
Hi,

I'm new to java script. I wrote this guessing game (with lots of help from other scripts), but how do i clear the textbox after a guess has been made ?

Thanks for any help.
Marlin


<HTML>
<HEAD>
<TITLE>Guess the number</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
hiddenNumber = Math.round((Math.random() * 1000))%1000 + 1;
function checkGuess(guess) {
if (guess > hiddenNumber) {
status=("Too high! Try again");
}
else if (guess < hiddenNumber) {
status=("Too low!Try again");
}
else if (guess == hiddenNumber)
status=("Congratulations! You guessed the number!");
}
function continueGame(){
var quit = confirm("Do you want to stop playing?");
if (quit == true)
window.close();
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Guessing Game</H1>
Guess a number between 1 - 1000:
<FORM NAME="guessForm">
<INPUT TYPE="text" NAME="guessField">
<INPUT TYPE="button" VALUE=" Guess "
onClick="checkGuess(document.guessForm.guessField.value);">
</FORM>
</BODY></HTML>

vwphillips
07-11-2006, 10:14 AM
<HTML>
<HEAD>
<TITLE>Guess the number</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
hiddenNumber = Math.round((Math.random() * 1000))%1000 + 1;
function checkGuess(obj) {
var status;
var guess=obj.value;
if (guess > hiddenNumber) {
status=(guess+" is Too high!\nTry again");
}
else if (guess < hiddenNumber) {
status=(guess+" is Too low!\nTry again");
}
else if (guess == hiddenNumber){
status=("Congratulations! You guessed the number!\n"+guess);
}
alert(status);
obj.value='';
}
function continueGame(){
var quit = confirm("Do you want to stop playing?");
if (quit == true)
window.close();
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Guessing Game</H1>
Guess a number between 1 - 1000:
<FORM NAME="guessForm">
<INPUT TYPE="text" NAME="guessField">
<INPUT TYPE="button" VALUE=" Guess "
onClick="checkGuess(document.guessForm.guessField);">
</FORM>
</BODY></HTML>

mkeehan
07-11-2006, 10:18 AM
try this


<HTML>
<HEAD>
<TITLE>Guess the number</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
hiddenNumber = Math.round((Math.random() * 1000))%1000 + 1;
function checkGuess(guessID) {

var guess = document.getElementById(guessID).value;

if (guess > hiddenNumber) {
status=("Too high! Try again");
}
else if (guess < hiddenNumber) {
status=("Too low!Try again");
}
else if (guess == hiddenNumber) {
status=("Congratulations! You guessed the number!");
}

document.getElementById(guessID).value='';

alert(status);
}

function continueGame(){
var quit = confirm("Do you want to stop playing?");
if (quit == true)
window.close();
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Guessing Game</H1>
Guess a number between 1 - 1000:
<FORM NAME="guessForm">
<INPUT type="text" id="guessField" name="guessField">
<INPUT type="button" value=" Guess "
onClick="checkGuess('guessField');">
</FORM>
</BODY></HTML>

- I left an alert in to test it.

Marlin
07-11-2006, 10:42 AM
Thanks alot for the help !!!:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum