0

Really hoping you can help me with this, I'm needing the user to enter a unique ID into a form, I then need javascript to create an iFrame with the javascript variable the user entered and part of the src URL.

<form>
<input type="text" id="Rname" name="Rname"><br>
</form> 
<button onclick="myFunction()">Start Room</button>
<iframe id="chatframe" src="" height="45%" width="80%" allow="camera; microphone" class="left"> 
</iframe>

<script> 
function myFunction() {

var x = Rname

document.getElementById("chatframe").src =
"https://meet.jit.si/"+ x;  
</script>

The code above doesn't work and im fairly certain it's due to it not being able to assign the user's input to the variable, then insert that variable into the iFrame... but I'm actually at a loss with this.

Many Thanks

PyPat848
  • 21
  • 5
  • Your JavaScript doesn't make any sense at all. Even the function is not closed. At all if your code would be working `meet.jit.si` will not allow you to use their web in Iframe because of `X-Frame-Options` and `SAMEORIGIN security reasons`. – Jax-p Mar 30 '20 at 23:16

1 Answers1

1

You need to close function inside script tag and use proper selector for input value.

Example:

    <script>
      function myFunction() {
        var x = document.getElementById("Rname").value;
        document.getElementById("chatframe").src = "https://meet.jit.si/" + x;
      }
    </script>

Also this might be useful for you in order to comprehend selectors:

How do I get the value of text input field using JavaScript?

valjic
  • 116
  • 3