/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Prompt does not work – no error message

Hi all –

Newbie to JavaScript.

I’m working through tutorials in
[I]JavaScript for the World Wide Web, Fifth Edition (Visual QuickStart Guide)”
Tom Negrino[/I]

I can’t figure out what is wrong with this script
When I run it in Firefox 2 I receive a blank screen
When I run it in IE 7, I receive:

[QUOTE]

This page requires JavaScript.

[/QUOTE]

As expected.

Could yo please point to what I might be doing wrong?
I’ve checked it several times and I don’t see it
Full code below

Thanks
-winston

[CODE]<?xml version=”1.0″ encoding=”UTF-8″?>
<DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>My Javascript Page</title>
<script language=”Javascript” type=”text/javascript”>
<!– Hide script from old browsers
ans = prompt(“Are you sure you want to do that?”,””)
If(ans){
alert(“You said “+ans)
}
else{
alert(“You refused to answer”)
}
// End hiding script from old browsers –>
</script>
</head>
<body bgcolor=”#FFFFFF”>
<noscript>
<h2>This page requires JavaScript.</h2>
</noscript>
</h1>
</body>
</html>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJun 05.2008 — Several errors.

1. need to finish each statement with a ';'

2. do not capitalize the 'if' command

3. missing <h1> start anchor

See:
[code=php]
<?xml version="1.0" encoding="UTF-8"?>
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Javascript Page</title>
<script language="Javascript" type="text/javascript">
<!-- Hide script from old browsers
ans = prompt("Are you sure you want to do that?","");
if (ans != '') { alert("You said "+ans); }
else { alert("You refused to answer"); }
// End hiding script from old browsers -->
</script>
</head>
<body bgcolor="#FFFFFF">
<noscript>
<h2>This page requires JavaScript.</h2>
</noscript>
<h1>OK</h1>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@GilaMonsterauthorJun 05.2008 — Thanks.

I would've sworn I fixed the case on if.

Corrected and work as expected

Final code below

Thanks

-winston

[CODE]<?xml version="1.0" encoding="UTF-8"?>
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Javascript Page</title>
<script language="Javascript" type="text/javascript">
<!-- Hide script from old browsers
ans = prompt("Are you sure you want to do that?","")
if(ans){
alert("You said "+ans)
}
else{
alert("You refused to answer")
}
// End hiding script from old browsers -->
</script>
</head>
<body bgcolor="#FFFFFF">
<noscript>
<h2>This page requires JavaScript.</h2>
</noscript>
</body>
</html>[/CODE]
×

Success!

Help @GilaMonster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...