Paul Smith
Paul Smith

Reputation: 173

get URL from ID

So i'm using http://goqr.me/ 's API to generate QR codes for download links on my site so people can download things straight to their mobile.

However the user can only Input the download link to a button as the QRcode is hard coded into the site, so i was wondering if it's possible to grab the URL of the button they generate and add it into the API of the QRcode generator.

I'm probably better off using javascript instead of the html API i'm using but i'm not very good with javascript.

some example code:

user submitted download button:

<a href="http://www.example.com" id="QRcode">Download</a>

QRcode:

<img src="https://api.qrserver.com/v1/create-qr-code/?data= #QRcode URL &size=115x115">

Upvotes: 0

Views: 243

Answers (1)

hakany
hakany

Reputation: 7254

HTML part:

<a href="http://www.example.com" id="QRcode" onclick="generateQrDownload(); return false;">Download</a>
<img id="qrImg" src="http://my_initial_url">

By using javascript you could grab the value from the input field and append to your url by using the following function in javascript

function generateQrDownload() {
    var url = 'https://api.qrserver.com/v1/create-qr-code/?data=' + document.getElementById('QRcode').href+ '&size=115x115';
    document.getElementById('qrImg').src = url;
}

Hope this helps.

Upvotes: 1

Related Questions