Wednesday 4 February 2009

Getting annoyed by my lack of coding knowledge

This morning I played on Animal Crossing until about 10am, then I copied the Animal pics over to my PC and sorted them into pics with me, Mac or Ben or more than one of us in them. That took until about 11am. Then I uploaded today's pics to Flickr so I could link them here in my blog.

Mr Resetti
Unfortunately it seems I didn't save properly yesterday, so all the money I made and the perfect snowman I made have been lost. Annoying.

Blowing bubbles
I went to town to see if Mr Resetti's reset station or whatever it's called was there. It wasn't, but there was a balloon seller there who gave me a bubble blower. I tried changing my hat to see if he wouldnt recognise me and give me another present like Jingle does, but he still recognised me :(

Lyle dancing
Whilst I was in town I went to the HRA building, and Mac's room was the display room. Lyle said the Gyroids made him want to dance.

Snowman
Then I made a monstrosity of a snowman (on purpose).

After that I checked my email, did a bit more work on panachallengetest, then it was lunch time.

After lunch I went on Animal again, then checked my email again and did some more work on panachallengetest for the rest of the afternoon. I got stuck for quite a while because I didn't understand variable scope in PHP, and it took me wuite a long time until I realised that variable scope was the problem. I'm used to javascript where you declare a variable outside a function and it is automatically global. In php you need to write global $myvar; inside the function to make the function treat $myvar as a global variable. The PHP Manual has a good guide to variable scope.

The other problem I had was with a javascript function I was writing to make a select box readOnly if a text input was filled in. (You can't set readOnly on a select for some cheeson). But Safari (only Safari, the other webkit browsers Chrome and Konqueror were okay) was firing an event twice when I did a blur() on a select element that had an onchange() event attached, or if I did a focus() onto another element from the select element with an onchange() event attached.

function toggleCameraSelect(e)
{
e = e || window.event;
var CameraSelect = document.forms['entryForm']['frm_camera'];
var NewCamera = document.forms['entryForm']['frm_new_camera'];
if(trim(NewCamera.value))
{

CameraSelect.selectedIndex = 0;
if((e.srcElement == CameraSelect) || (e.target == CameraSelect))
{
alert("You can't change the camera model when you have specified a new one");
NewCamera.focus();
}
}
}
toggleCameraSelect(window);
addEvent(document.forms['entryForm']['frm_new_camera'], 'change', toggleCameraSelect);
addEvent(document.forms['entryForm']['frm_camera'], 'change', toggleCameraSelect);


I must have spent at least 2 hours trying to find out how to fix it, but in the end, the solution was pretty simple - change the selectedIndex of the select box after doing the alert, and in the conditional statement for the alert add a condition that the selectedIndex must not be 0. I thought that this would mean the event would still fire twice in Safari, but the alert would only occur once. However, it seems that now Safari only fires the event once.
function toggleCameraSelect(e)
{
e = e || window.event;
var CameraSelect = document.forms['entryForm']['frm_camera'];
var NewCamera = document.forms['entryForm']['frm_new_camera'];
if(trim(NewCamera.value))
{
if(((e.srcElement == CameraSelect) || (e.target == CameraSelect)) && CameraSelect.selectedIndex != 0)
{
alert("You can't change the camera model when you have specified a new one");
NewCamera.focus();
}
CameraSelect.selectedIndex = 0;
}
}
toggleCameraSelect(window);
addEvent(document.forms['entryForm']['frm_new_camera'], 'change', toggleCameraSelect);
addEvent(document.forms['entryForm']['frm_camera'], 'change', toggleCameraSelect);


In the evening I found out how to fix that problem above, then finished watching House of Flying Daggers with Mac and Ben. Then I watched Flight of the Conchords and The Office (US) with Mac.

Then I did some more work on panachallengetest. Unfortunately the subversion commands in Netbeans aren't entirely obvious what they do e.g. Update - does that overwrite my file with one downloaded from the server or upload my file to the server? Anyway, I hope I did it correctly.

The weather today was nice and sunny with a blue sky most of the day, though clouded over a bit later in the afternoon. Quite a bit of the snow melted out the front where the sun shone most of the day, but in the back garden, though the snow has melted a bit, it's still quite snowy.

Food
Breakfast: hot cross bun with butter; cup o' tea.
Lunch: Breaded ham with salad sandwich
Dinner: 2 slices of Pepperoni pizza; chips; peas. Pudding was spotted dick with custard. Coffee.
Supper: Coffee; Fox's crinkle crunch.

No comments: