Advertisement
MizunoBrasil

Javascript 01

Jan 27th, 2023
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.     <head>
  3.         <meta charset="UTF-8">
  4.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  7.         <title>Cadastro</title>
  8.     </head>
  9.     <body>
  10. <div class="container">
  11.     <br><br><br>
  12.     Imagem ou vídeo do youtube?
  13.     <br><br><br>
  14. <form action="saveData.php" method="post">
  15.   <div class="form-check">
  16.   <input type="radio" class="form-check-input" name="mediaType" value="image" onclick="generateTag()"> Image
  17. </div>
  18.   <div class="form-check">  
  19.   <input type="radio" class="form-check-input" name="mediaType" value="youtube" onclick="generateTag()"> Youtube Video
  20.   </div>
  21.   <br>
  22.   <div class="form-group">
  23.   <textarea class="form-control" id="output" name="output"></textarea>
  24.   </div>
  25.   <input type="hidden" id="hiddenOutput" name="hiddenOutput" value="">
  26.   <input type="submit" class="btn btn-primary" value="Save" onclick="document.getElementById('hiddenOutput').value = document.getElementById('output').value">
  27. </form>
  28.  
  29. <script>
  30.       function generateTag() {
  31.         var radioValue = document.querySelector('input[name="mediaType"]:checked').value;
  32.         var textArea = document.getElementById("output");
  33.         if (radioValue === "image") {
  34.           textArea.innerHTML = '<img src="" alt="" class="img-fluid">';
  35.         } else if (radioValue === "youtube") {
  36.           textArea.innerHTML = '<div class="embed-responsive embed-responsive-16by9"> <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/" allowfullscreen></iframe> </div>';
  37.         }
  38.         document.getElementById('hiddenOutput').value = textArea.innerHTML;
  39.       }
  40.     </script>
  41.  
  42.     </div>
  43.     </body>
  44.     </html>
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement