0

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

2
  • 2
    Can you explain what you are trying to do a little bit better. The example code is extremely wrong and it's hard to figure out what you're trying to do. Commented Oct 19, 2011 at 9:25
  • 2
    I'd suggest starting with a basic JavaScript tutorial. Commented Oct 19, 2011 at 9:26

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

A better source of information is the MDN JavaScript Guide: developer.mozilla.org/en/JavaScript/Guide
0

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>

2 Comments

Why is document.write needed here? Why not simply remove the script tag?
To add encodeURIComponent(document.location) to the link. You have to scroll to see it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.