Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I’m trying to code a browser, but the button is not responsive. What should I do?

Here’s what I tried :

<input id="query" type="text" maxlength="32" size="50" placeholder="Search using GoogGoog..."></input>
  <button id="search">Go</button>

  <br>
  
  <script type="text/javascript">
    document.getElementById("search").onclick = function () {
      if document.getElementById("query") == "chimic" {
        location.href = "https://kornls.github.io/googgoog/dev/chimic.html";
      } else {
        location.href = "https://kornls.github.io/googgoog/dev/search.html";
    };
  </script>

But the button won’t redirect to any of the pages when clicked. What should I do?

Any help is appreciated. Thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s because of incorrect syntax.
Firstly, ( should come after the if and before document and at the end after "chimic" and before {

i.e. if (document.getElementById("query") == "chimic") {

Secondly, function block is opened with { but not ended. The } before the </script> should NOT have a semicolon, and this brace is ending the else block, not the function block.

<script type="text/javascript">
    document.getElementById("search").onclick = function () {
      if (document.getElementById("query") == "chimic") {
        location.href = "https://kornls.github.io/googgoog/dev/chimic.html";
      } else {
        location.href = "https://kornls.github.io/googgoog/dev/search.html";
      }
    }
</script>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading