Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-09-2012, 01:06 AM   PM User | #1
samhor
New Coder

 
Join Date: Mar 2012
Location: USA
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
samhor is an unknown quantity at this point
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>
samhor is offline   Reply With Quote
Old 05-09-2012, 01:47 AM   PM User | #2
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
answered

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

The corrected code seems to work.
low tech is offline   Reply With Quote
Old 05-09-2012, 02:07 AM   PM User | #3
samhor
New Coder

 
Join Date: Mar 2012
Location: USA
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
samhor is an unknown quantity at this point
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>
samhor is offline   Reply With Quote
Old 05-09-2012, 07:37 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:34 PM.


Advertisement
Log in to turn off these ads.