473,569 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getE lementById('but ton2');
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 31770
FantaJ wrote:
Hi,

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

var x=document.getE lementById('but ton2');
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.visibil ity = 'hidden';

and to make it visible again:

x.style.display = '';
or
x.style.visibil ity = '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*********@gm ail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .

Hi,

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

var x=document.getE lementById('but ton2');
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">M y Button</button>
<button onclick="toggle Visibility('myB utton');">Hide/show My
Button</button>
<button onclick="toggle Display('myButt on');">Remove/restore My
Button</button>
<script type="text/javascript">
function toggleDisplay(i d) {
var el;
if (document.getEl ementById) {
el = document.getEle mentById(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 toggleVisibilit y(id) {
var el;
if (document.getEl ementById) {
el = document.getEle mentById(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*****@agrico reunited.com>
comp.lang.javas cript 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
2209
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
1616
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 javascript will be run only in some conditions determine by the input of some webcontrols. Finally the server side event will depend on the chioce of user...
3
1856
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 and show a label saying "Processing" How can i do this using the attributes.add code ??? thanks in advance C
2
1828
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 the button when it is disabled. Below is a snippet: document.all.btnSignIn.src="Images/sign_in_disabled.gif"; This code correctly changes the...
1
1418
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 validator I want to force my html button to follow the validator, how to do it? Any help is very appreciated...
4
6469
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; HEIGHT: 24px" type="reset" value="Reset" name="btnReset1" runat="server"> Using Interdev I then double click the button in design view and in the code...
1
4504
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 if they tried to 'machine gun' type thing using their mouse to submit repeatedly I guess this can be considered an HTML problem not PHP but im...
1
5452
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 the page for other reasons and the item disappears. The reason it disappears is I have to set the state initially to invisible so it doesn't show up...
5
6849
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 OnClick function but that won't work because the button control has the focus. I traced and put a trap at the top of form_current but it didn't hit...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.