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 6029591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:54:32+00:00 2026-05-23T04:54:32+00:00

i’m aiming to put 2 search forms on the same wordpress page. i’m using

  • 0

i’m aiming to put 2 search forms on the same wordpress page. i’m using the iframe form code and have already sorted out how to direct that to a search element.

but the form includes the following script:

http://www.google.com/cse/brand?form=cse-search-box&lang=en

which starts by defining the search box by ID

var f = document.getElementById(‘cse-search-box’);

but if you use multiple forms then you (incorrectly i know) end up with elements that have the same ID.. and the branding+ focus/blur events don’t work across both forms.

the form basically looks like:

<form action="/search.php" class="cse-search-box">
<div>
<input type="hidden" name="cx" value="" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" size="32" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="//www.google.com/cse/brand?form=cse-search-box&lang=en"></script>

if this were a jquery script i think it’d be easy to change the ID to a class name and do an .each() iteration. but google’s code is pure javascript and i’m not familiar with that, though
i read getElementbyClass isn’t super reliable.

so is this fixable or not worth worrying over?

  • 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-05-23T04:54:33+00:00Added an answer on May 23, 2026 at 4:54 am

    eventually i commented out that script from google.com and replaced it w/ my own custom version:

    `
    if (window.history.navigationMode) {
    window.history.navigationMode = ‘compatible’;
    }

    jQuery.noConflict();
    jQuery(document).ready(function($) { //tells WP to recognize the $ variable
    
        //from google's original code- gets the URL of the current page
        var v = document.location.toString();
        var existingSiteurl = /(?:[?&]siteurl=)([^&#]*)/.exec(v);
        if (existingSiteurl) {
        v = decodeURI(existingSiteurl[1]);
        }
        var delimIndex = v.indexOf('://');
        if (delimIndex >= 0) {
        v = v.substring(delimIndex + '://'.length, v.length);
        }
    
    
        $(".cse-search-box").each( function() { 
            var q = $(this).find("input[name=q]");
            var bg = "#fff url(http:\x2F\x2Fwww.google.com\x2Fcse\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_custom_search_watermark.gif) left no-repeat";
            var b = "#fff";
          if (q.val()==""){
            q.css("background",bg);
          } else {
            q.css("background",b);
          }
          q.focus(function() {
            $(this).css("background", b);
            });
            q.blur(function() {
                if($(this).val()==""){
                    $(this).css("background", bg);
                }
            });
    
            //adds hidden input with site url
            hidden = '<input name="siteurl" type="hidden" value="'+ v +'">'
            $(this).append(hidden);
        });
    
    
    }); //end document ready functions
    

    `

    and on the search.php page that you are directing the results to (so this is a 2-page search form, i found a tutorial on that online somewhere) you will need:

    `
    google.load(‘search’, ‘1’, {language : ‘en’, style : google.loader.themes.MINIMALIST});

      /**
       * Extracts the users query from the URL.
       */ 
      function getQuery() {
        var url = '' + window.location;
        var queryStart = url.indexOf('?') + 1;
        if (queryStart > 0) {
          var parts = url.substr(queryStart).split('&');
          for (var i = 0; i < parts.length; i++) {
            if (parts[i].length > 2 && parts[i].substr(0, 2) == 'q=') {
              return decodeURIComponent(
                  parts[i].split('=')[1].replace(/\+/g, ' '));
            }
          }
        }
        return '';
      }
    
      function onLoad() {
        // Create a custom search control that uses a CSE restricted to
        // code.google.com
        var customSearchControl = new google.search.CustomSearchControl)('google_search_id');
    
        var drawOptions = new google.search.DrawOptions();
        drawOptions.setAutoComplete(true);
    
        // Draw the control in content div
        customSearchControl.draw('results', drawOptions);
    
        // Run a query
        customSearchControl.execute(getQuery());
      }
    
      google.setOnLoadCallback(onLoad);
    

    `

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.