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


basically have far page has 2 pop-up/alert boxes. first asks user input name of favorite website. second asks user input url favorite website. outcome supposed display in hyperlink on homepage name user entered directs url entered when clicked on. here code looks like:

<!doctype html> <html>     <head>         <title>untitled</title>     </head>     <body>         <script type="text/javascript">             var favoritesite;             favoritesite = prompt ("what favorite web site?")             favoritesite = prompt ("what url of site?")              document.write('<a href="' + favoritesite + '"></a>')         </script>                                <h1>link favorite site.</h1>         <h2>this favorite web site</h2>       </body> </html> 

ps. very beginner javascript, assistance appreciated. thanks.

this ended changing to:

<html>     <head>         <title>untitled</title>     </head>     <body>         <script type="text/javascript">             var favoritesite;             var favoritesitename;             favoritesitename = prompt ("what favorite web site?");             favoritesite = prompt ("what url of site?");              document.write("<h1>link favorite website.</h1>");             document.write("<h2>this favorite web site" +" " +     favoritesitename.link("https://" + favoritesite + "") + "</p>");         </script>                            </body> </html> 

what have almost correct.

var favoritesitename = '',     favoritesiteurl = '';  favoritesitename = prompt('what favorite web site?'); favoritesiteurl = prompt('what url of site?'); document.write('<a href="' + favoritesiteurl + '">' + favoritesitename + '</a>'); 

you missing semi-colons indicate end of lines , adding site name link. also, h1 , h2 elements don't belong inside script element.

jsfiddle.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -