0

I'm trying to make a program that takes user input and changes a variable with that input and create an iframe. For example, if the user input was https://google.com it would create an Iframe of Google. Here is my code:

<html>
  <input id="url" type="text" placeholder="https://" /><button
            onclick="document.getElementById('input').value"
          >
          <script src=
          ./script.js></script>
</html>

That is the HTML, and here is the Javascript:

var thing = (document.getElementById('input').value)
function iframe(){ var a,b,c;c="$thing", b=document.createElement("iframe"), b.setAttribute("src",c),b.setAttribute("id","rusic-modal"), b.setAttribute("style","position: fixed; width: 100%; height: 100%; top: -2; left: -2; right: 0; bottom: 0; z-index: 99999999999; background-color: #fff;"), a=document.getElementsByTagName("body")[0],a.appendChild(b)})).call(this)

I don't understand why its not working. I'm decently versed in javascript but I'm no master.

  • You're calling `getElementById('input')` even tho the ``'s ID is `url`. – 0stone0 Mar 31 '20 at 16:48
  • So I need to set both of them to url? – arze-dev Mar 31 '20 at 16:50
  • As @0stone0 points out, it should be `document.getElementById('url')` or `document.querySelector('input')`. Further, your template string should be using backticks instead of quotations, and curly braces around the variable: `\`${thing}\`` – tlong314 Mar 31 '20 at 16:53
  • Actually, why even bother with template literals. Just use `c = thing`. – tlong314 Mar 31 '20 at 16:56
  • I'm now getting ```SyntaxError: Unexpected token ')' at /script.js:2:352``` and I'm not sure where it is – arze-dev Mar 31 '20 at 16:57
  • Why is this closed as duplicated for `string interpolation` ?? This has nothing to do with it! – 0stone0 Mar 31 '20 at 16:59

1 Answers1

0

You should use `` for string with variable and also add {} after $ It should looks like this

c = `${thing}`

Tryout this