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 Coder
    Join Date
    Mar 2012
    Location
    USA
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to make text appear after the prompt.

    Hello All,

    I have made a prompt and marked it in bold below. I would like text to appear after what the person has entered

    At current it reads Hello (Name Prompt)

    I would like it to appear saying something on the lines of Hello (Name Prompt) Enjoy The Game.

    Any Ideas?

    <html>
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    <head>
    <TITLE>Find the Correct Number Game</TITLE>
    </head>


    a=(prompt('please enter your name:',0)); // prompt for player name

    document.write(' Hello ' ,a);


    var guessme=Math.round(Math.random()*(49)+1);
    var speech='Choose a number between 1 and 50';

    function process(hiddennumber) {
    var guessnumber=document.forms.guesstable.guessnumber.value;
    var speech='"'+guessnumber+ '" Letters are not allowed. Please enter digits only!.';
    document.forms.guesstable.guessnumber.value='';

    if (guessnumber==hiddennumber)
    {
    document.forms.guesstable.prompt.value='Congratulations! '+hiddennumber+' is correct!';
    alert ('Well done - the mystery number is '+hiddennumber+'! \n\nIf you want to play again click the button.');
    speech='';
    document.location=document.location;
    }

    if (hiddennumber<guessnumber)
    {
    speech='Less than '+ guessnumber;
    }

    if (hiddennumber>guessnumber)
    {
    speech='Greater than '+ guessnumber;
    }

    if (guessnumber=='')
    {
    speech='You didn\'t guess anything!'
    }

    document.forms.guesstable.prompt.value=speech; document.forms.guesstable.guessnumber.focus();

    }


    </SCRIPT>
    </body>
    </html>

    <FORM onSubmit="" NAME="guesstable">
    <CENTER>
    <TABLE ALIGN="left" BGCOLOR="#888889" BORDER="5" CELLPADDING="5">
    <TR>
    <TD BGCOLOR="#004081">
    <FONT COLOR="#ffffff" FACE="Arial"><B>Find the Correct Number</B></FONT>
    </TD>
    </TR>
    <TR>
    <TD>
    <CENTER>
    <INPUT TYPE="text" NAME="prompt" SIZE="31" MAXLENGTH="60" VALUE="Find the correct number which is between 1 and 50"><BR>
    <INPUT TYPE="text" NAME="guessnumber" SIZE="3" MAXLENGTH="3" VALUE="">
    <INPUT TYPE="button" VALUE="Enter" onClick='process(guessme)'>
    </CENTER>
    </TD>
    </TR>
    </TABLE>
    </CENTER>
    </FORM>

  • #2
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    answered

    http://www.codingforums.com/showthread.php?t=260617

    The corrected code seems to work.

  • #3
    New Coder
    Join Date
    Mar 2012
    Location
    USA
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    prompt issue still there

    Yeah i changed the code to the below but i would like text to appear after the prompt. So it would appear saying Hello (NAME ENTERED IN TO THE PROMPT) Enjoy the game.

    The Enjoy the game part doesn't appear the prompt stops working when i add it in. Any ideas?

    <body>
    <html>
    <head>
    <title>Find the Correct Number Game By sam Horne</title>
    <H1><font color="black">Find the Correct Number Game</font></H1>


    <SCRIPT LANGUAGE='javascript'>

    a=(prompt('Please enter your name:',0)); // prompt for player name
    document.write(' Hello ' ,a) Enjoy the Game



    var guessme=Math.round(Math.random()*(49)+1);
    var speech='Choose a number between 1 and 50';

    function process(hiddennumber) {
    var guessnumber=document.forms.guesstable.guessnumber.value;
    var speech='"'+guessnumber+ '" Letters are not allowed. Please enter digits only!.';
    document.forms.guesstable.guessnumber.value='';

    if (guessnumber==hiddennumber)
    {
    document.forms.guesstable.prompt.value='Congratulations! '+hiddennumber+' is correct!';
    alert ('Well done - the mystery number is '+hiddennumber+'! \n\nIf you want to play again click the button.');
    speech='';
    document.location=document.location;
    }

    if (hiddennumber<guessnumber)
    {
    speech='Less than '+ guessnumber;
    }

    if (hiddennumber>guessnumber)
    {
    speech='Greater than '+ guessnumber;
    }

    if (guessnumber=='')
    {
    speech='You didn\'t guess anything!'
    }

    document.forms.guesstable.prompt.value=speech; document.forms.guesstable.guessnumber.focus();

    }


    </SCRIPT>
    </body>
    </html>

    <FORM onSubmit='' NAME='guesstable'>
    <CENTER>
    <TABLE ALIGN='left' BGCOLOR='#888889'>
    <TR>
    <TD BGCOLOR='#004081'>
    <FONT COLOR='#ffffff" FACE='Arial'><B>Find the Correct Number</B></FONT>
    </TD>
    </TR>
    <TR>
    <TD>
    <CENTER>
    <INPUT TYPE='text' NAME='prompt' SIZE='50' MAXLENGTH='60' VALUE='Find the correct number which is between 1 and 50'><BR>
    <INPUT TYPE='text' NAME='guessnumber' SIZE='3' MAXLENGTH='3' VALUE=''>
    <INPUT TYPE='button' VALUE='Submit' onClick='process(guessme)'>
    </CENTER>
    </TD>
    </TR>
    </TABLE>
    </CENTER>
    </FORM>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,144
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Code:
    <script type = "text/javascript">
    var a=(prompt('Please enter your name:',"")); // prompt for player name 
    document.write(" Hello " + a + " Enjoy the game!");
    var guessme=Math.floor(Math.random()*50+1);  // generates 1 - 50 truly randomly
    var speech= prompt('Choose a number between 1 and 50', "");
    <script language=javascript> is long deprecated. Use <script type = "text/javascript"> instead (in fact also deprecated but still necessary for IE<9).

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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