Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
How to load HTML file into HTML use JS with button

I what to load the b.js file to HTML with button and function. when user type "yes" and click on "Ok" button, "b.js" must load in page (not open in new window or new tab)

what code I must to use in ??????????? place to solve my problem? here is the code:

HOME.html

<html>
<head>
</head>
<body>
<form name="load">yes OR no<input name="id" type="text">
<input type="button" value="OK" onClick="my(document.forms.load)">
<script>
function my(form) {
    if (form.id.value=="yes") {              

?????????????
   
        } else {
            alert("NO")
        }
}
</script>
</body>
</html>

b.js

document.write(`

<html>
<h1> Load the HTML code</h1>
</html>

`);

I tried to use <script src="b.js"></script> but this code immediately load "b.js" that I dont what this

I tried to use

var scriptTag = document.createElement('script');
scriptTag.setAttribute('src','b.js');
document.head.appendChild(scriptTag)

but not working

I tried to use

document.getElementsByTagName('body')[0].innerHTML += "<script src='b.js'></script>";

but this code not working

what can I do to load the "b.js" file after click on button?

thanks :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Is this what you're looking gor?

function my(form) {
  const loadHTML = () => {
    const scriptB = document.createElement('script')
    scriptB.setAttribute('src','b.js')
    console.log(scriptB)
    document.write(`
      <h1>Load the HTML code</h1>
      ${scriptB.outerHTML}
    `);
  }
  if (form.id.value==="yes") {
    loadHTML()
  } else {
    alert("NO")
  }
}
<html>
<head>
</head>
<body>
<form name="load">
  <h2>YES or NO</h2>
  <input name="id" type="text">
  <input type="button" value="OK" onClick="my(document.forms.load)">
</form>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda