Tuesday, 3 September 2013

I am trying to create a link on an HTML page using information that a user inputs via JavaScript alert box

I am trying to create a link on an HTML page using information that a user
inputs via JavaScript alert box

Basically what I have so far is a page that has two pop-up/alert boxes.
The first asks the user to input the name of their favorite website. The
second asks the user to input the URL to their favorite website. The
outcome is supposed to display in a hyperlink on the homepage as the name
the user entered that directs to the URL they entered when clicked on.
Here is what my code looks like:
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script type="text/javascript">
var favoriteSite;
favoriteSite = prompt ("What is your favorite web site?")
favoriteSite = prompt ("What is the URL of that site?")
document.write('<a href="' + favoriteSite + '"></a>')
</script>
<h1>Link to favorite site.</h1>
<h2>This is my favorite web site</h2>
</body>
</html>
PS. I am a very very beginner to JavaScript, any assistance would be
appreciated. Thanks.

No comments:

Post a Comment