473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

prompt not working

I'm just starting out with javascript and the following is not working
as it should. The expected prompt dialog box never appears.

<head>
<script language="JavaScript"><!--
var name;
name=prompt("Please enter your name.","");
document.write("My name is: ", name);
// --></script>
</head>
<body>
<p>Did it work out ok?
</body>
</html>

I've tried replacing
<script language="JavaScript">
with
<script type="text/javascript">
but this makes no difference in the results, which are as follows:

My name is:

Did it work out ok?

What am I doing wrong?

Joe

Nov 30 '05 #1
13 10655
VK

joemac wrote:
I'm just starting out with javascript and the following is not working
as it should. The expected prompt dialog box never appears.

<head>
<script language="JavaScript"><!--
var name;
name=prompt("Please enter your name.","");
document.write("My name is: ", name);
// --></script>
</head>
<body>
<p>Did it work out ok?
</body>
</html>

I've tried replacing
<script language="JavaScript">
with
<script type="text/javascript">
but this makes no difference in the results, which are as follows:

My name is:

Did it work out ok?

What am I doing wrong?


I donno... It works as it posted, maybe your did not type the name in?

Few advises though: document.write() clears the document content after
the page has been finished to load. It is almost never what you want.
You may want to use DOM methods instead. And DOM methods are not
realibly available until the page finished to load (neither your
functions). Thus the preffered sequence would be:

1) You load the page first
2) The "load" event calls your function
3) Your function does all imaginable (and unimaginable ;-) things with
your page

<html>
<head>
<title>Hello world!</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<script type="text/javascript">

// Global variable:
var myName = "";

function myFunction() {
// Local variable:
var sysOut = document.getElementById("sysOut");

myName = prompt("Please enter your name:","");

if (myName) {
sysOut.innerHTML = "Your name is: " + myName;
}
else {
sysOut.innerHTML = "You did not tell me your name... :-(";
}
}
</script>

</head>

<body onload="myFunction()">

<div id="sysOut">Did it work out ok?</div>

</body>

</html>

Nov 30 '05 #2
>I donno... It works as it posted, maybe your did not type the name in?

As I said, the dialog box does not appear - so there is no place for me
to type in the name.
Few advises though: document.write() clears the document content after
the page has been finished to load. It is almost never what you want.
You may want to use DOM methods instead.


Thanks for the tip but at this point I am simply following the
instructions as given in the book that I am using to learn the
language. If it is not the best approach then I'm sure the author will
explain that later on and give new examples. Since you said the code
worked for you as posted then it must be viable. There must be
something different about my runtime environment which causes it not to
work for me, and this is what I need to get to the bottom of.

I tried executing the code that you provided as a counter example and
it likewise did not work for me as it should have. No prompt box
appeared and I got the following result:

You did not tell me your name... :-(

Joe

Nov 30 '05 #3
VK
joemac wrote:
I tried executing the code that you provided as a counter example and
it likewise did not work for me as it should have. No prompt box
appeared and I got the following result:

You did not tell me your name... :-(


It means then that

Option A) You browser doesn't support JavaScript - highly unlikely
but...

Option B) You raised security settings too high so JavaScript became
disabled on your browser.

In the latter case (if Internet Explorer):
1) run Internet Explorer
2) Tools > Internet Options... > Security tab
3) Select "Internet" zone and click "Custom level"
4) Find the "Active scripting" section and set it to "Enable"
The rest of settings you may leave is they are.

If you don't want (or not allowed) to change any settings, then you
have to go to http://www.mozilla.org, get the newest version of Firefox
browser and use it to learn JavaScript. And use Internet Explorer to
browse the Internet.

Nov 30 '05 #4
VK wrote:
joemac wrote:
I tried executing the code that you provided as a counter example and
it likewise did not work for me as it should have. No prompt box
appeared and I got the following result:

You did not tell me your name... :-(
It means then that

Option A) You browser doesn't support JavaScript - highly unlikely
but...


I'm using IE version 6. Seems unlikely to me as well.
Option B) You raised security settings too high so JavaScript became
disabled on your browser.

In the latter case (if Internet Explorer):
1) run Internet Explorer
2) Tools > Internet Options... > Security tab
3) Select "Internet" zone and click "Custom level"
4) Find the "Active scripting" section and set it to "Enable"
The rest of settings you may leave is they are.


I thought maybe we were onto something here but it turns out that my
Active Scripting was already Enabled. I checked my "Intranet" settings
as well and it is enabled there also.

Any other ideas?

Thanks, Joe

Nov 30 '05 #5
VK

joemac wrote:
Any other ideas?


Where is no more, sorry...

My variant of script is working for sure.
IE 6 has default support for JScript for sure.
You are saying that JScript is enabled.

But it ignores the script - it means that something of three statements
above is wrong.

I just checked the script again - it works. It is so primitive - there
is no space for an error. Plus someone would point it already out.

IE 6 indeed supports JScript: this common knowledge fact can be easily
checked at microsoft.com.

So: JScript is disabled on your browser. I have no idea how is it
possible. Maybe you have some overly-agressive 3rd party anti-virus
which strips out any script from the page? The problem seems not
reparable remotely.

For the time being go to <http://www.mozilla.com> and download Firefox
1.5 (it's only 5Mb). Install it and open the test page in it to see if
it works. This is the only way to know if crazy things are going with
your IE browser or with your Windows.

Nov 30 '05 #6
Well my test page works fine under FireFox so I guess the problem must
lie somewhere within IE. If anyone has any ideas what the problem
could be, please post. Thanks.

Joe

VK wrote:
joemac wrote:
Any other ideas?


Where is no more, sorry...

My variant of script is working for sure.
IE 6 has default support for JScript for sure.
You are saying that JScript is enabled.

But it ignores the script - it means that something of three statements
above is wrong.

I just checked the script again - it works. It is so primitive - there
is no space for an error. Plus someone would point it already out.

IE 6 indeed supports JScript: this common knowledge fact can be easily
checked at microsoft.com.

So: JScript is disabled on your browser. I have no idea how is it
possible. Maybe you have some overly-agressive 3rd party anti-virus
which strips out any script from the page? The problem seems not
reparable remotely.

For the time being go to <http://www.mozilla.com> and download Firefox
1.5 (it's only 5Mb). Install it and open the test page in it to see if
it works. This is the only way to know if crazy things are going with
your IE browser or with your Windows.


Nov 30 '05 #7
joemac wrote:
Well my test page works fine under FireFox so I guess the problem must
lie somewhere within IE. If anyone has any ideas what the problem
could be, please post. Thanks.


Please don't top post, reply below quoted text and trim unnecessary
material.

I'd suggest moving the document.write (actually the whole script)out of
the head element. MS have given the 'prompt' method an optional default
text parameter that Firefox seems to ignore.

In IE 6 if the default text isn't specified, 'undefined' is put into the
prompt input field, which unsettles some users. Try the following:
<html>
<head><title>Write test</title></head>
<body>
<script type="text/javascript">
var aName = prompt('Enter your name please','');
document.write(aName);
</script>
</body>
</html>
If that doesn't work, Google 'mark of the web'.

[...]

--
Rob
Dec 1 '05 #8
Lee wrote:

Since you know that you should use "text/javascript", why did you
post code with the obsolete form, instead?
I *don't* know which form of usage is correct. According to the text
that I'm using ("Introduction to Interactive Programming on the
Internet using HTML & JavaScript", by Craig D. Knuckles), "<script
language="JavaScript">" is the correct form of usage. The only reason
I got the idea of trying "<script type="text/javascript>" is because I
took a look at some sample code on a web site geared towards Javascript
programmers.
Don't use "name" as a variable. The window already has an attribute
called "name".

Try this:

<html>
<head>
<script type="text/javascript>
var myName;
myName=prompt("Please enter your name.","");
document.write("My name is: ", myName);
</script>
</head>
<body>
<p>Did it work out ok?</p>
</body>
</html>


Ok, I tried your example above and it doesn't work for me either.
There must be something wrong with my IE configuration but I have no
idea what.

Joe

Dec 1 '05 #9
RobG wrote:
joemac wrote:
Well my test page works fine under FireFox so I guess the problem must
lie somewhere within IE. If anyone has any ideas what the problem
could be, please post. Thanks.
Please don't top post, reply below quoted text and trim unnecessary
material.


Ok.
I'd suggest moving the document.write (actually the whole script)out of
the head element. MS have given the 'prompt' method an optional default
text parameter that Firefox seems to ignore.

In IE 6 if the default text isn't specified, 'undefined' is put into the
prompt input field, which unsettles some users. Try the following:
<html>
<head><title>Write test</title></head>
<body>
<script type="text/javascript">
var aName = prompt('Enter your name please','');
document.write(aName);
</script>
</body>
</html>
Tried it. Doesn't work. I noticed that you used single rather than
double quotes for the prompt parameters. Was that intentional or a
typo? If single quotes are the correct way of specifying strings in
JavaScript then perhaps the text I'm learning from is too rife with
mistakes to be useful.
If that doesn't work, Google 'mark of the web'. From what I just read about it it seems to only be an issue in Windows

XP SP 2. I am running Windows 2000 Professional SP 4. Let me know if
I'm wrong ... if it is in fact also an issue for Win2k. Thanks.

Joe

Dec 1 '05 #10
joemac wrote:
Lee wrote:
Since you know that you should use "text/javascript", why did you
post code with the obsolete form, instead?
I *don't* know which form of usage is correct.


Bad enough.
According to the text that I'm using ("Introduction to Interactive
Programming on the Internet using HTML & JavaScript", by Craig D.
Knuckles), "<script language="JavaScript">" is the correct form of
usage.
Burn it. Obviously its content is either completely wrong or badly
outdated. (The HTML 4.01 Specification is dated December 24, _1999_).
The only reason I got the idea of trying "<script type="text/javascript>"
is because I took a look at some sample code on a web site geared towards
Javascript programmers.


<URL:http://validator.w3.org/> pretty much tells you what is correct
regarding HTML and what is not.

<URL:http://www.pointedears.de/scripts/mime-types/> (which I had no
time to complete with your responses yet, sorry) tells you what is
current, and pretty much tells you what is the prudent MIME type and
what is not.
PointedEars
Dec 1 '05 #11
joemac wrote:
RobG wrote:

[...]
<html>
<head><title>Write test</title></head>
<body>
<script type="text/javascript">
var aName = prompt('Enter your name please','');
document.write(aName);
</script>
</body>
</html>

Tried it. Doesn't work. I noticed that you used single rather than
double quotes for the prompt parameters. Was that intentional or a
typo? If single quotes are the correct way of specifying strings in
JavaScript then perhaps the text I'm learning from is too rife with
mistakes to be useful.


Intentional. I like to use double quotes in HTML and single in script,
it makes it the target environment more obvious.

If that doesn't work, Google 'mark of the web'.


From what I just read about it it seems to only be an issue in Windows

XP SP 2. I am running Windows 2000 Professional SP 4. Let me know if
I'm wrong ... if it is in fact also an issue for Win2k. Thanks.


Just fishing! I get the same behaviour, Thomas does not. He is using
Firefox on Linux, we are on Windows.

This seems to be already reported as a bug:

<URL: https://bugzilla.mozilla.org/show_bug.cgi?id=312466 >

--
Rob
Dec 1 '05 #12
Thomas 'PointedEars' Lahn wrote:

<URL:http://validator.w3.org/> pretty much tells you what is correct
regarding HTML and what is not.


I ran my code through the above validator. First time it complained
about the missing DOCTYPE, so I added one. Second time it strongly
recommended a Character Encoding specification, so I added one. On the
third pass it gave it's seal of approval that the code is valid.
Delightful! Now if someone could explain why it still doesn't work I'd
be ecstatic. Here is the modified version...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=ISO-8859-1">
<TITLE>Java Script Test</TITLE>
<SCRIPT TYPE="text/javascript">
var myName;
myName=prompt("Please enter your name.","");
document.write("My name is: ", myName);
</SCRIPT>
</HEAD>
<BODY>
<p>Did it work out ok?
</BODY>
</HTML>

Joe

Dec 1 '05 #13
joemac wrote:
Thomas 'PointedEars' Lahn wrote:
<URL:http://validator.w3.org/> pretty much tells you what is correct
regarding HTML and what is not.
I ran my code through the above validator. First time it complained
about the missing DOCTYPE, so I added one. Second time it strongly
recommended a Character Encoding specification, so I added one.


Be sure you also serve it with the correct Content-Type HTTP header.
<URL:http://web-sniffer.net/>
[...] Now if someone could explain why it still doesn't work I'd
be ecstatic. Here is the modified version...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
So far you set browsers with DOCTYPE sniffing to use Compatibility/Quirks
Mode.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

will trigger Standards Compliance Mode of browsers. The W3C Markup
Validator does not tell you this because it uses an SGML parser that
uses an catalog file and looks up the system identifier (the URI of
the DTD) there, matching it against the public identifier (that you
already included above.)

<http://www.w3.org/TR/html4/struct/global.html#h-7.2>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=ISO-8859-1">
<TITLE>Java Script Test</TITLE>
<SCRIPT TYPE="text/javascript">
var myName;
myName=prompt("Please enter your name.","");
That is the same as

var myName = prompt("Please enter your name.", "");
document.write("My name is: ", myName);
Try

document.write("My name is: " + myName);

instead.
</SCRIPT>
</HEAD>
<BODY>
<p>Did it work out ok?
Even if not required in HTML 4.01 Transitional, you should
include the close tag </p>.
</BODY>
</HTML>


(Even though HTML is case-insensitive in that regard, it
is a Good Thing to lowercase all tag and attribute names.)

You have not moved the `script' element into the `body'
element as was suggested before. Try that first.
HTH

PointedEars
Dec 1 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dr John Stockton | last post by:
The following DOS prompt command line, in a Win98 DOS box, cscript //nologo ~tmp.js executes file ~tmp.js as javascript/Jscript. The following batch file, similarly run, executes the same....
1
by: Taffy Collins | last post by:
I have an ASP page that contains an A HREF tag. This will load a new page and carry some variables to the new page. What I want is that, whenever a person click the item,the prompt box comes up and...
4
by: glenn | last post by:
I keep reading all sorts of books on VS that keep telling me to click on Tools/Visual Studio Command prompt to run this program or that program. However, I do not have such a menu choice. Where is...
5
by: joemac | last post by:
I'm just starting out with javascript and the following is not working as it should. The expected prompt dialog box never appears. <head> <script language="JavaScript"><!-- var name;...
5
by: hcross | last post by:
This project is a web based html and Javascript site. I am working on mac at the moment. This script works except for attempting to open new window once complete. As you can see, i am new to...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
3
by: sigkill9 | last post by:
I've been working on this script all weekend and am almost done with it accept for one last detail; implementing a "process another number?" prompt after a user input is processed. The script...
4
by: sdanda | last post by:
Hi, I am working on C# windows applications.What i want to do is, I want to Redirect the output from Command Prompt to the Rich Text Box, Actually i am unable to read the entire output of the comman...
1
by: Rob Nicholson | last post by:
I've managed to write an ASP.NET v2 web page where the prompt to save the password doesn't appear :-( Not sure why it's not working. Autocomplete on the text boxes is working but when you enter...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.