|
-
Jun 13th, 2006, 08:50 PM
#1
Thread Starter
Addicted Member
[RESOLVED] How to disable button
Hi
I want to disable button when I click it.
How can I do it in PHP?
Thanks
-
Jun 13th, 2006, 10:17 PM
#2
Hyperactive Member
Re: How to disable button
It's best done with Javascript.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 13th, 2006, 10:20 PM
#3
Re: How to disable button
Yes as the PHP won't run until the form is submitted and the page reloaded.
Use the JS "disabled" property.
-
Jun 14th, 2006, 12:47 AM
#4
Thread Starter
Addicted Member
Re: How to disable button
OK
How can I do it in JavaScript?
-
Jun 14th, 2006, 01:05 AM
#5
Re: How to disable button
You can use the onclick event in Javascript:
Code:
onclick="this.setAttribute('disabled', 'disabled');"
-
Jun 14th, 2006, 01:59 AM
#6
Re: How to disable button
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 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.
HTML Code:
<!-- ... -->
<head>
<script type="text/javascript" src="event-listeners.js"></script>
</head>
<!-- ... -->
<button id="myButton">Click me</button>
Javascript:
Code:
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
-
Jun 14th, 2006, 12:59 PM
#7
Thread Starter
Addicted Member
Re: [RESOLVED] How to disable button
-
Jun 14th, 2006, 04:19 PM
#8
Thread Starter
Addicted Member
Re: [RESOLVED] How to disable button
OK
There's something else.
How can I add JS code above to HTML Editor (e.g. Front Page)?
-
Jun 14th, 2006, 04:41 PM
#9
Lively Member
Re: [RESOLVED] How to disable button
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
-
Jun 15th, 2006, 04:01 AM
#10
Re: [RESOLVED] How to disable button
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++.
-
Jun 15th, 2006, 04:53 AM
#11
Re: [RESOLVED] How to disable button
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..
- ØØ -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|