0
<button id="btn" onclick="download(http://imageurl) value ="download"><button>    


<script>
  function download(url){
 console.log(url);
var link = document.createElement('a');
              link.href = url;
              link.download = "image.jpg";
              document.body.appendChild(link);
              link.click();}
</script>

Syntax error: ) missing after the argument list?

3
  • close the braces - } Commented Aug 25, 2016 at 15:27
  • @TeymurMardaliyerLennon: Not sure you would get that error from the braces missing... for example, Chrome would say: Unexpected end of input Commented Aug 25, 2016 at 15:29
  • 1
    Pro-tip: format your code correctly. It makes it much easier for people and yourself to debug your code as well as add new functionality. Commented Aug 25, 2016 at 15:37

2 Answers 2

3

You are missing quotes in the HTML. Both the close " for the onclick attribute, and you need to wrap your parameter in single quotes to make it a string:

<button id="btn" onclick="download('http://imageurl')" value ="download"><button>
Sign up to request clarification or add additional context in comments.

Comments

2

You have to pass your arguments as a string from within the HTML, in the onclick method.

 <button id="btn" onclick="download('http://imageurl')" value ="download"><button>

The way that you wrote it created a syntax error, and that is why you got that error message.

1 Comment

Interesting that your original answer doesn't show in the edit history...

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.