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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:21:23+00:00 2026-06-07T18:21:23+00:00

I am trying to build a little search script, but can’t seem to stop

  • 0

I am trying to build a little search script, but can’t seem to stop the page from re-loading when you hit submit. There is probably something wrong with my code:

function searchThat(e) {
    if (!e) e = window.event;
    e.preventDefault();

    if (searchFor.indexOf(searchIn) != -1) {
        console.log('we found it');
    }
}

Thanks a bunch!

I am calling it with

    if (searchFor && searchIn && searchSubmit) {
    addEvent(searchSubmit, 'submit', searchThat)
    }

and:

function addEvent(elem, evtType, func) {
    if (elem.addEventListener) {
        elem.addEventListener(evtType, func, false);
    } else if (elem.attachEvent) {
        elem.attachEvent("on" + evtType, func);
    } else {
        elem["on" + evtType] = func;
    }
}

and the HTML:

<div class="container">
    <form>
        <p>Search for:</p>
        <p class="mrm">
            <input type="text" id="searchFor" name="searchFor">
        </p>
        <p>In:</p>
        <textarea class="mrm" type="text" id="searchIn" name="searchIn"></textarea>
        <p>
            <input type="submit" class="clicker nmb" id="searchSubmit" name="searchSubmit">
        </p>
    </form>
</div>
  • 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-07T18:21:24+00:00Added an answer on June 7, 2026 at 6:21 pm

    <Input type="submit"/> will always trigger postback and reload the page.
    If it works with whatever you’re trying to implement change your input to <Input type="button"/>

    And

    addEvent(searchSubmit, 'click', searchThat)
    {}
    

    There could be more logic that your code is missing but from what you’ve posted you can make your life even easier by instead of doing all this complicated JScripting you can just do:
    <Input type="button" value="Click Me" onclick="searchThat()"/>

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

Sidebar

Related Questions

I'm trying to build my little app for cydia submission ... but I can't
I have a site I'm trying to build and I've hit one little snag
Maybe my question it's a little weird, but I'm trying to build a not-so-simple
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm building my first rails app and I'm trying to build the search page
I'm trying to build a little bit advanced users system using Joomla, but I
I am trying to build a lucene index through hibernate search FullTextSession.createIndexer().startAndWait() but even
I'm trying to build a little script that would let me do this: http://example.com/appicons.php?id=284417350
I'm trying to write a little build script, and want to determine if the
I'm trying to create myself a little build script to build a project for

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.