473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Make html button disappear with javascript?


Hi,

Is it possible to make a html button invisible using javascript?
I can certainly disable it:

var x=document.getElementById('button2');
x.disabled=true;
//x.type = 'hidden'; // read only?
//x.visible = false; // doesn't exist?

but is there a property i can (ab)use to make it invisible?

Thanks in advance.

Aug 5 '05 #1
3 31748
FantaJ wrote:
Hi,

Is it possible to make a html button invisible using javascript?
I can certainly disable it:

var x=document.getElementById('button2');
x.disabled=true;
//x.type = 'hidden'; // read only?
input type hidden is not the same as readonly - the user can't see it
so in that sense a readonly input it's not readable at all.
//x.visible = false; // doesn't exist?

but is there a property i can (ab)use to make it invisible?
You can hide elements using:

x.style.display = 'none';
or
x.style.visibility = 'hidden';

and to make it visible again:

x.style.display = '';
or
x.style.visibility = 'visible';

The difference is that display 'none' will make the element take up
zero space in the page and hence will likely affect page layout.
Visibility just hides/shows the element with no effect on page layout.

Thanks in advance.


--
Rob
Aug 5 '05 #2
Thanks Rob - just what i was looking for.

Aug 5 '05 #3
"FantaJ" <vi*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

Hi,

Is it possible to make a html button invisible using javascript?
I can certainly disable it:

var x=document.getElementById('button2');
x.disabled=true;
//x.type = 'hidden'; // read only?
//x.visible = false; // doesn't exist?

but is there a property i can (ab)use to make it invisible?

Thanks in advance.


<button id="myButton">My Button</button>
<button onclick="toggleVisibility('myButton');">Hide/show My
Button</button>
<button onclick="toggleDisplay('myButton');">Remove/restore My
Button</button>
<script type="text/javascript">
function toggleDisplay(id) {
var el;
if (document.getElementById) {
el = document.getElementById(id);
} else if (document.all) {
el = document.all[id];
}

if (el && (el = el.style) && ('string' == typeof el.display)) {
el.display = ('none' == el.display ? '' : 'none');
}
}
function toggleVisibility(id) {
var el;
if (document.getElementById) {
el = document.getElementById(id);
} else if (document.all) {
el = document.all[id];
}

if (el && (el = el.style) && ('string' == typeof el.visibility)) {
el.visibility = ('hidden' == el.visibility ? 'visible' :
'hidden');
}
}
</script>
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Aug 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Howard Jess | last post by:
: In HTML 4.01, a <button> element can take 1 of 3 types: type=submit (default) type=reset type=button The Javascript to create a button element dynamically is
4
by: Lau Alvin | last post by:
HI all , I want to make a button which have a server side OnClick event in .cs to update the DB. But I want it to have a client side onclick event to run a javascript popup too. And the...
3
by: Colin Graham | last post by:
I have been working on a form to update a database when i enter details and click a button. My issue is that some of the users click the button twice. I want to remove the button when i click it...
2
by: abarberis | last post by:
I am writing an asp.net application which is using image buttons for the interface. I have some buttons that have a enabled and disabled state. I have written javascript code to change the image on...
1
by: Bishoy George | last post by:
I have an html button that reads a text box and runs a javascript. I made a Required Validator on that text box , any web button follows that validator. My html button does not follow the...
4
by: Ryan | last post by:
Hello, I have a standard HTML button on an aspx web form that I have set to runat server. The button is named reset1 and its tag is as follows: <INPUT id="btnReset1" style="WIDTH: 60px;...
1
by: mdburton | last post by:
onclick="this.href='javascript:void(0)';this.disabled=1"> ive tried that, but it renders it useless and doesnt make it 'submit' it should be able to work, but so the user cannot submit it twice...
1
by: Mufasa | last post by:
I have a couple of radio buttons that make various things appear/disappear on the screen through JavaScript. All works great. Problem is I'll click a radio button, something will appear, I reload...
5
by: Susan Bricker | last post by:
I have a command button that I'd like to make "disappear" after being clicked and after the OnClick function has executed. I have tried changing the 'visible' attribute to false while within the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.