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

136
Views
Execute two functions with one button click

I'm having a time trying to figure this one out. First, let me say I'm a total javascript novice, but I haven't figured this out. I want to run two separate functions, both referencing the value in the search box created in the code. The idea is, the script will search for the value in the search box, opening up 2 new tabs, each searching the value accompanied by different secondary terms prescribed in the code. What do I need to get this script to run?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Programmable Search Engine Two</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <section>
      <div class="main">
        <div class="searchBox">
          <input type="text" name="" class="query" value="" />
        </div>
        <div class="button">
          <button class="searchBtn">Search</button>
        </div>
      </div>
    </section>
    
<script type="text/javascript">

let query = document.querySelector(".query");
      let searchBtn = document.querySelector(".searchBtn");
 
 searchBtn.onclick = "function One(); function Two();"

    function One() {
    let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";
    window.open(url, (target = "blank"))

    },

    function Two() {
    let url = "https://www.google.com/search?q=" + query.value + " " + "hotels";   
    window.open(url, (target = "blank"))
    
    };

</script>

  </body>
</html>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You should change

searchBtn.onclick = "function One(); function Two();"

to

searchBtn.addEventListener('click', function() {
  One();
  Two();
})
about 4 years ago · Juan Pablo Isaza Report

0

You can use Element.setAttribute() to set the onclick of searchBtn to call both One() and Two() by changing:

searchBtn.onclick = "function One(); function Two();"

to:

searchBtn.setAttribute("onclick", "One(); Two();");

const query = document.querySelector(".query");
const searchBtn = document.querySelector(".searchBtn");
searchBtn.setAttribute("onclick", "One(); Two();");

function One() {
    console.log(`Called function One() when query=${query.value}`); 
};

function Two() {
    console.log(`Called function Two() when query=${query.value}`);
};
<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Programmable Search Engine Two</title>
      <link rel="stylesheet" href="style.css" />
   </head>
   <body>
      <section>
         <div class="main">
            <div class="searchBox">
               <input type="text" name="" class="query" value="" />
            </div>
            <div class="button">
               <button class="searchBtn">Search</button>
            </div>
         </div>
      </section>
   </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!