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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help clearing a textbox

    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

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

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,536
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this

    Code:
    <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.

  • #4
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks alot for the help !!!


  •  

    Posting Permissions

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