Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!