Jump to content

How to insert <a> in a document.write method?


Recommended Posts

Hello fellas. I'm trying to make a "menu" using JS and php.The trick is that the document.write() has to contain an <a href="link"> and this link has to be a variable that i define in the top of the document.The question is. Can i insert variables as a link inside the document.write() method?My current code is:

<table border="1" cellpadding="2" cellspacing="0" width="130px"> <tr>  <td>  <script type="text/javascript">  document.write('<a href="' + PageDA + '"><img src="Engelsk_flag.jpg" border=1" /></a>')  </script>  </td> </tr></table>

The link doesn't work. I dont know how to insert the variable into a link.If i can't do that how do i then work it out ?

Link to comment
Share on other sites

Ok. Fixed the quotation mark, and worked on it abit. still doesn't work.The variables that i want to call is in the head section of the page. Should be fine and cool.It looks like this:

<script type="text/javascript">var Location="Basic Information"var PageEN="infoEN.php"var PageDA="infoDA.php</script>

Then my newly made script looks like this (still doesn't work)

<table border="1" cellpadding="2" cellspacing="0" width="130px"> <tr>  <td align="center">  <script type="text/javascript">  document.write('<a href="' + PageEN + '"><img src="Engelsk_flag.jpg" border="1" /></a>')  document.write('<a href="' + PageDA + '"><img src="Dansk_flag.jpg" border="1" /></a>')  </script>  </td> </tr> <tr>  <td align="center">Change Language</td> </tr></table>

Still dont know what is wrong X.x

Edited by Stefan B. W
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...