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

  • Home
  • SEARCH
  • 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 6580421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:01:39+00:00 2026-05-25T16:01:39+00:00

I tried to hide elements in my html form by defining a javascript function

  • 0

I tried to hide elements in my html form by defining a javascript function at the beginning of my page and calling it through a button’s onclick attribute. It seems like the browser (firefox 4.x) tries initially to hide the given element when I click the button, but then quickly reloads it. Without the script, obviously, no attempt is made by the browser to hide the element. Here is the pertinent code:

function showHide() {
document.getElementById('search').style.display = 'none';
}


<button onclick="showHide()">Advanced</button>

Does firefox default to what it finds in the css file instead of using the javascript modifications?

Edit #1:
First off, I am trying to get an text edit field to disappear. When I click on the “Advanced” button, it does disappear for a fraction of a second and then reappears. I tried returning false at the end of showHide(), but that did nothing, and I tried onclick=”return showHide();” but that didn’t work as well. I checked the css file, and there are no display: settings that could conflict with this. I’ll see if I can’t get this up on my server in a few minutes and post the link.

Edit #2: Thanks for the help. Changing the type attribute of the button fixed the issue by preventing the button from defaulting to “submit,” as suggested below. This kept the form from being reloaded, which was causing the element to reappear every time it tried to go away. Not something a beginner like me would have known.

  • 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-25T16:01:39+00:00Added an answer on May 25, 2026 at 4:01 pm

    The html <button> element supports a type attribute. If omitted, it defaults to type="submit". This causes the button to work exactly like an <input type="submit" />.

    So… if your button is located inside a form, then clicking the button causes the click handler to run (calling showHide()), but then it submits the form. It is the form submission that is causing the page reload.

    To fix this, simply add the proper type to your button:

    <button type="button" onclick="showHide()">Advanced</button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to show a form once a certain button is clicked. i tried
I've got an input field on my plain html form that I would like
Another jQuery issue... I have tried this several times using class and id elements
I wonder if anyone can help. An HTML div in a page of mine
I would like to hide a div when a button is clicked and show
I have a php form and I want to display or hide certain fields
I'm trying to change a '+' into '-' when toggling elements. I've tried a
I have found this code (jQuery): $('.toggle').click(function() { $('.container').eq($(this).index()).toggle('fast'); }); This is my HTML:
I tried to hide a couple of element so that the end users can
I am trying to hide/unhide some table cells o a page, and I find

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.