-2

I'm attempting to output a link from a page of a site back to the linking site.

invoiceNo & rawPrice are variables that are extracted from the page prior to this and values extracted and converted to the appropriate string and float values.

If I hard code values in (invoice001) and (29.99), for example, the script runs fine. However, as it stands all that happens is the variable name being displayed in the link.

Any help would be greatly appreciated.

Thanks

<script type="text/javascript">
window.invoiceData = $('h2').text();
window.invoiceNo = invoiceData.substr(14);
window.priceBeforeCurrencyStrip = $('td.priceCol.balance').text();
window.price = parseFloat(priceBeforeCurrencyStrip.match(/[0-9.]+/));
</script>

<script type="text/javascript" 
        src="https://.......&SaleID='+invoiceNo+'&OrderVal='+price'">
</script>
2
  • 1
    Show us what you've tried. Commented Oct 14, 2014 at 20:36
  • 2
    Learn How to Ask a question on StackOverflow Commented Oct 14, 2014 at 20:37

1 Answer 1

1

This should fix your problem, your main problem was with quotes and scopes

<script type="text/javascript">
    var invoiceData = $('h2').text();
    var invoiceNo = invoiceData.substr(14);
    var priceBeforeCurrencyStrip = $('td.priceCol.balance').text();
    var price = parseFloat(priceBeforeCurrencyStrip.match(/[0-9.]+/));
    var url = "www.google.com/test.js"

    var script = document.createElement('script');
    script.setAttribute("src","http://"+url+"&SaleID="+invoiceNo+"&OrderVal="+price);
    script.setAttribute("type","text/javascript");
    var body = document.getElementsByTagName("body");
    body.appendChild(script);
</script>
Sign up to request clarification or add additional context in comments.

5 Comments

Sincerely, I've never seen this. So I went and tried it myself, and all I got was a invalid request to the invalid URL https://url%26saleid%3D/, and the following message in my Chrome Dev Tools: (failed) net::ERR_NAME_NOT_RESOLVED
That's because you need to change the url bit to be the url of the script you want
Afraid not, looking at the page source it's now showing as a broken link and the 2 variables are still displaying as just the variable names.
The point is, I've never heard of JS variables laying around side by side with the <script> attributes. That doesn't seem valid HTML or JS to me.
My bad, I went full stupid.... Fixed it so it dynamically loads a script

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.