Click to See Complete Forum and Search --> : [RESOLVED] How to disable button
onh1986
Jun 13th, 2006, 08:50 PM
Hi
I want to disable button when I click it.
How can I do it in PHP?
Thanks
PlaGuE
Jun 13th, 2006, 10:17 PM
It's best done with Javascript.
penagate
Jun 13th, 2006, 10:20 PM
Yes as the PHP won't run until the form is submitted and the page reloaded.
Use the JS "disabled" property.
onh1986
Jun 14th, 2006, 12:47 AM
OK
How can I do it in JavaScript?
visualAd
Jun 14th, 2006, 01:05 AM
You can use the onclick event in Javascript:
onclick="this.setAttribute('disabled', 'disabled');"
penagate
Jun 14th, 2006, 01:59 AM
There is also the newer way which is to use DOM event listeners. Since IE as usual has its own way of doing things I've made wrapper functions (dev.penagate.spiralmindsinc.com/js/event-listeners.js) for these. Download the file and then reference it to your page using a <script> element in your <head> section (don't reference my URL, apart from nicking my bandwidth I might delete or move that file yet). Use addEHandler() to add a click event once the window has loaded.
<!-- ... -->
<head>
<script type="text/javascript" src="event-listeners.js"></script>
</head>
<!-- ... -->
<button id="myButton">Click me</button>
Javascript:
addEHandler(window, 'load', doOnload);
function doOnload()
{
addEHandler(document.getElementById('myButton', 'click', doBtnClick));
}
function doBtnClick(e)
{
var obj = e.target || e.srcElement;
obj.setAttribute('disabled', 'disabled');
}
While on the face of it it's a ton more code, it has the advantage of not polluting your HTML markup with Javascript code, thus keeping it neat and content-centric. This principle should be followed for CSS styling as well. Always have your CSS in an external stylesheet (for non-trivial pages) or a <style> block in the <head> section (for trivial pages). Seperating content from presentation and scripting also means you can easily update each bit individually.
Information overload? Probably. But that's web design for you. If you take the easy way, we'll all have crap websites :)
onh1986
Jun 14th, 2006, 12:59 PM
Thanks very much
onh1986
Jun 14th, 2006, 04:19 PM
OK
There's something else.
How can I add JS code above to HTML Editor (e.g. Front Page)?
cx323
Jun 14th, 2006, 04:41 PM
go into code view and paste it in. make sure ou put the top one in the head section and the rest in your body code
penagate
Jun 15th, 2006, 04:01 AM
FrontPage is an airborne piece of flaming bovine excrement. Please do not ever use it to make a page that's going to on the WWW.
I recommend Notepad++ (notepad-plus.sourceforge.net).
NoteMe
Jun 15th, 2006, 04:53 AM
NotePad or NoteMe, potato, potaato, Frontpage is depricated as of 2006. they will come out with a totaly new application soon. But untill we have computers that can translate wrong to right Emacs is the way to go..:)
- ии -
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.