Hi
I want to disable button when I click it.
How can I do it in PHP?
Thanks
Printable View
Hi
I want to disable button when I click it.
How can I do it in PHP?
Thanks
It's best done with Javascript.
Yes as the PHP won't run until the form is submitted and the page reloaded.
Use the JS "disabled" property.
OK
How can I do it in JavaScript?
You can use the onclick event in Javascript:
Code:onclick="this.setAttribute('disabled', 'disabled');"
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.
Javascript:HTML Code:<!-- ... -->
<head>
<script type="text/javascript" src="event-listeners.js"></script>
</head>
<!-- ... -->
<button id="myButton">Click me</button>
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.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');
}
Information overload? Probably. But that's web design for you. If you take the easy way, we'll all have crap websites :)
Thanks very much
OK
There's something else.
How can I add JS code above to HTML Editor (e.g. Front Page)?
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
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 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..:)
- ØØ -