Reputation: 1
I want the javascript to link the data from the url, but this is not working.
I tried the following code:
<script language="javascript">
<span class="buttonAction"><a href="checkout_shipping.php?info=document.writeln(document.location);">
<img src="images/checkout.png" width="93">
</a></script>
can anyone help me with this ? many thanks
Upvotes: 0
Views: 81
Reputation: 472
You can't put html in a javascript tag. If you want to print the link you can do it like this:
<script language="javascript">
document.write('<span class="buttonAction"><a href="checkout_shipping.php?info='+encodeURIComponent(document.location)+'"><img src="images/checkout.png" width="93" alt=""/></a><span>');
</script>
Upvotes: 0
Reputation: 10665
You cannot put html in a script tag. Some pointers: Put the html above the script, give the a tag an id and use javascript to set the href attribute from the script part.
<span class="buttonAction">
<a id="thelink" href="">
<img src="images/checkout.png" width="93">
</a>
</span>
<script language="javascript">
// insert javascript code to set the href attribute here (read a javascript tutorial)
</script>
see: http://www.w3schools.com/js/default.asp, http://www.w3schools.com/jsref/met_doc_getelementbyid.asp
(this solution is the closest to your original code, later you might prefer to move your javascript elsewhere and/or start using javascript framework)
Upvotes: 1