I’ve ceased to be able to tell the difference between SNL’s Tina Fey and Palin - not helped by the fact that Fey often seems to be just quoting Palin.
When you’re filling in an HTML form and you hit Return / Enter, your browser will submit the form as if you clicked the default button… which is always the first submit button in the form. Sometimes though, you don’t want the default button to be the first one.
I’ve seen some funky solutions to this problem, including using a hidden submit button which appears first in the form, but I’ve found the following works fine - change all the submit buttons that you don’t want to be default to normal buttons, i.e., type="button" instead of type="submit", and use their onclick events to submit the form. For example:
<form id="myform" method="get"> <!-- Not the default button --> <input name="b1" type="button" onclick="this.form.submit()" value="B1" /> <!-- The default button --> <input name="b2" type="submit" value="B2" /> </form>
If only we lived in a world where everybody used non-IE browsers. Web design would be so much easier. The latest thing I’ve discovered IE 7 can’t do, is display a PNG favicon. What can you do?
- Make a sweet little 16×16 PNG favicon in your favorite paint application
- Butcher it into an ICO file using favicon.cc
- Upload both files to your web server
- Stick the following code in the HEAD section of your webpage
- Reassure yourself that IE users are pretty used to a sub-standard web browsing experience, and won’t be bothered by the lack of proper transparency or 24bit color in the favicon they see
<link rel="icon" type="image/png" href="favicon.png" /> <!--[if IE]> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> <![endif]-->
After a long summer of waiting (the weather made it feel more like a long winter), I’ve got a start date - September 29th. That’s when I’ll be starting a week of training in Boston, going to the Partners in Health symposium, and meeting the team there. The following week I’ll be flying to Kigali… where I’ll be for possibly a year.
As I mentioned before, I’m going to be mentoring local computer programmers so they can work on an electronic medical records system built on OpenMRS. I’ll be responsible for a small group of students and will teach and set exercises to develop their programming skills. Rwanda is an exciting place for a computer geek like me - the government has ambitious plans to become the IT hub of Central Africa, and if they get this medical records system going, they’ll be doing better than us in the UK!
I’m really looking forward to being back in Rwanda - the warm air, the banana trees, the thunder and lightning, the crazy matatu taxis and the red dirt that gets everywhere!
My friend Tom sent me the video below - a song written by Brooke Fraser when she got back from Rwanda. I’m not usually a Hillsongs kind of guy but I like this song, and the video is gorgeous.
Scenario: you make a nice HTML form for some purpose. A user comes along and spends some time filling it in… and then clicks a link on the page and loses everything they wrote. User never comes back to your site.
What you need is a little bit of Javascript to check for unsaved changes and warn the user before they leave the page if they are going to lose their work. Gutuma uses something like the following:
var is_post_back = false; window.onbeforeunload = function (ev) { var html = document.send_form.msg_html.value; var subject = document.send_form.msg_subject.value; if (!is_post_back && (html != "" || subject != "")) return "Your message will be lost if you leave this page."; } function cancel_unsaved_warning() { is_post_back = true; }
The cancel function is called in the onclick events of any buttons on the page which do a POST back to the page, and thus won’t lose the user’s work. This is the best way I think to cancel the warning message as setting window.onbeforeunload = null doesn’t work in IE6, and returning anything from the onbeforeunload handler results in a warning message (even null or false), so you have to use some logic to avoid a return statement altogether. Weird but it works.
UPDATE 11/09/08: I’ve just discovered that IE treats javascript: hrefs as navigations away from the page and fires the onbeforeunload event. So you can’t call a javscript function like
<a href="javascript:myfunc()">Link</a>
without seeing the above warning message about leaving the page. But you can get around this by using the onclick attribute:
<a onclick="javascript:myfunc()" href="#">Link</a>
So you may have noticed a few posts which don’t make sense to a normal person. Well you can safely ignore them. I’ve been doing a bit of web development of late, and I’ve found random blog posts an essential source of information. First thing I do when I get stuck on a problem is fire it into Google and see who else has had the same problem and what was their solution. I figured I should share what I know in case its of use to anyone.
If you think AJAX is some Greek dude and JAVA is a kind of coffee, then you can subscribe to just my personal posts using this feed.
Another problem I ran into in the course of my recent development of a PHP newsletter tool (Gutuma), was the restriction on AJAX requests to the same domain as the host page. I’ve developed some AJAX gadgets which can be placed on a user’s site and will send subscription requests to the newsletter tool… which might be hosted on a different domain.
If you’ve come across an “Access to restricted URI denied” error then you’re probably having the same problem. The solution is to use a proxy on the domain where the AJAX controls are hosted. This proxy receives the HTTP requests from the AJAX controls and can forward them on to the other domain.
For an example of how to do this, you can check out guproxy.php which is my simple single file PHP script for forwarding AJAX requests (from the SACK AJAX library) to the AJAX interface of Gutuma. As a security precaution it limits forwarded requests based on the destination url, and the filters the POST variables to those used by Gutuma. Other solutions I’ve seen don’t do this and thus leave your proxy script open to abuse.
Recently I’ve been working on PHP mailing list tool, and I wanted to make a simple Javascript API so that users can place dynamically generated gadgets onto their own pages. I wanted one JS file that could be included on a page, but as I was using a 3rd party AJAX Javascript library, this also had to be included. Unfortunately Javascript has no concept of an include or import statement. So my solution was to use some PHP to merge them on the server:
<?php header('Content-Type: application/x-javascript'); ?> /** * This file is a server-side merge of first.js and second.js * * ------------------------------ first.js ------------------------------- */ <?php echo file_get_contents('first.js'); ?> /** * ---------------------------- second.php ---------------------------- */ <?php echo file_get_contents('second.js'); ?>
This simple approach could be used where you’ve got a lot of JS files and you want to speed up access times.
Call me naive, but I did think for a while there that Obama was going to start taking substantial Christian votes from the Republican party. Surely here was a guy, whose policies towards the poorer members of society Christians would identify with.
But alas all I hear are the same old polarised politics - Christians so convinced that Jesus would vote Republican that they don’t even stop to think about who to vote for.
Or they make it all about a few select moral issues - abortion, gay marriage etc. Now I’m as opposed to abortion anyone, but abortion didn’t disappear during the last 8 years of Bush’s presidency. Very little changed. And isn’t it a moral issue when the rich get richer and the poor get poorer, or when the poorest members of society struggle to afford basic health care?
Or the protests of “he’ll raise our taxes!”, as if that would be the worst thing in the world. Putting aside the fact that Obama has now pledged to cut taxes for 95% of working families, and that Americans generally pay much less tax than their European counterparts, maybe Jesus wants to see the rich pay more tax.
Once upon a time God gave a group of people a very detailed set of instructions for how their society should function. He instructed them to treat every 50th year as a special year - a year of Jubilee, and on that year all land had to be given back to its original owners. Does that sound like free-market capitalism? If a politician suggested that we’d call them a communist!
So my plea is as simple as this -take some time to think about who you are going to vote for.

