Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8628047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:26:10+00:00 2026-06-12T08:26:10+00:00

I have some code here: <html> <script type=text/javascript> document.getElementById(‘myElement’).onclick = function () { var

  • 0

I have some code here:

<html>
<script type="text/javascript">
    document.getElementById('myElement').onclick = function () 
    {
        var searchterm = document.getElementById('bereich').value;
        document.href("http://www.google.com/serach?q=" + searchterm);
    }
</script>
<body>
<center>
    <img src="https://www.google.de/images/srpr/logo3w.png"><br>
    <input type="text" name="q"> &nbsp; <input type="button" value="Search" onclick="startSearch()">
</center>

which does not work. I know this is such a noob stuff at all, but I don´t know javascript. Can anyone help me please?

Addition:

I also tried:

<html>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> &nbsp; <input type="button" value="Search" onclick="startSearch()">
</center>
<script type="text/javascript">
     window.onload = function(){
document.getElementById('myElement').onclick = function () 
{
    var searchterm = document.getElementById('bereich').value;
    document.href = "http://www.google.com/serach?q=" + searchterm;
}
     };

and:

<html>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> &nbsp; <input type="button" value="Search" name="searchButton" onclick="startSearch()">
</center>
<script type="text/javascript">
function triggerGoogleSearch() 
{
var searchterm = document.getElementById('bereich').value;
document.href("http://www.google.com/serach?q=" + searchterm);
}   

document.getElementById('searchButton').onclick = triggerGoogleSearch();
</script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:26:12+00:00Added an answer on June 12, 2026 at 8:26 am

    Change this:

    document.getElementById('myElement').onclick = function ()
    

    to this:

    function startSearch ()
    

    and change this:

    document.href("http://www.google.com/serach?q=" + searchterm);
    

    to this:

    window.location.href = "http://www.google.com/serach?q=" + searchterm;
    

    And also add id="bereich" to your <input type="text" name="q"> like this:

    <input type="text" name="q" id="bereich">
    

    if you want to find it by getElementById.

    Also, change the url from:

    http://www.google.com/serach
    

    to this:

    http://www.google.com/search
    

    UPDATE:

    Actually never mind all of those corrections and forget about JavaScript!

    Just make a simple HTML form:

    <img src="https://www.google.de/images/srpr/logo3w.png"><br>
    <form action="http://www.google.com/search" method="get">
    <input type="text" name="q">
    <input type="submit" value="Search">
    </form>
    

    See THIS DEMO.

    I think that we were all trying to fix your code and completely missed a much simpler solution. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create a HTML page with some JavaScript code. Here is the code
I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>
I have some code as shown below: - (IBAction)startButtonPressed:(id)sender { statusText.text = @Processing...; //here
I have some code here that uses bitsets to store many 1 bit values
I have some code here which works perfectly in firefox but not in chrome
I have some code here to call minizip(), a boilerplate dirty renamed main() of
I have some code that is using SyncEnumerator. As you can see here ,
I am trying to reduce some code here. I will explain how I have
I'm writing some code here, and I'm having a had time. I have a
I have this loop for (it= someCollection.iterator; it.hasNext(); ) { //some code here }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.