Friday, 7 November 2008

Getting annoyed by javascript browser incompatibilities

This morning just did some more work on my website, again didn't get much done.

First I had a problem with IE not supporting Node.prototype to add a new method (insertAfter) to the DOM. I did quite a bit of googling and reading, but didn't come up with anything that works the same way as insertBefore i.e. parentElement.insertBefore(newElement, existingElement), so just had to go with a simple insertAfter function i.e. insertAfter(newElement, existingElement).

Next I found that IE wouldn't change the type of an input element to hidden instead of text. So I had to just change its className to 'hidden' (a css class I have made with display: none) instead.

Then I tried to get javascript to select the correct option in a dropdown select box of country names. Unfortunately it didn't work at first, and it took me ages to find what was wrong. The problem was that the javascript was being called when a reset button was clicked. So the javascript was working, then the reset button would reset the form back to how it was before, so it looked like the javascript wasn't working. The solution was to return false at the end of the javascript function, and for the onclick of the reset button I had to change it to 'return jsfunction' so that the value of false was actually returned to the rest button.

When the 'edit' button is clicked at the bottom of my form it uses javascript to change and insert several elements. Then it changes to a cancel button, which when clicked makes the form go back to its previous state. What I had been doing previously was that the cancel function would have to go through the form and reset any changes and remove any inserted elements. This came to quite a bit of code, and the more changes you make when the edit button is clicked, the more changes you have to make when cancelling, so the cancel code was quite a few lines.

I decided to change this, so at the start of the edit function a copy of the form is made using var formOriginal = formElement.cloneNode(true). Then for the cancel/reset function all you need to do is formElement.replaceNode(formOriginal). Except this doesn't work. Again I spent quite a while googling and reading and testing to see what the problem is, and it turns out that replaceNode is an IE specific extension. It turns out you need to use replaceChild e.g. formElement.parentNode.replaceChild(formOriginal, formElement). A very useful page that lists the different DOM methods and properties and which browsers support them is www.quirksmode.org/dom/w3c_core.html.

So that's all working now, only problem is that there isn't way to add country data for records that don't already have any country data. So I'll have to work on that next.

After lunch I checked my email. The weather was quite nice this morning, definitely better than the past week of cloud and rain with no sun. So I was thinking of going out this afternoon (couldn't go out this morning because I had to look after granny), but unfortunately by the afternoon the sky was covered in cloud.

I was going to go on the rowing machine for a bit and watch an episode of MacGyver, but then Clare asked me to dig up a bush root in the front garden, so I had to do that instead. When I'd finished digging that up it was about 3.10pm and the weather had got nicer again with some clouds and the sun shining. I wanted to go out on a walk and maybe get some photos in the nice warm late afternoon light, but both Clare and Brian had gone out again so I had to stay in and look after granny. Unfortunately they were still both out near sunset time as well, and it was a nice sunset with the clouds lit up with the warm orange glow of the sun.

The post arrived at about 5.10pm! I started watching an episode of MacGyver in Maccy's room, then it was dinner tyme. After dinner I finished watching MacGyver, then watched Lost with Maccy and Ben. After that me and Mac were going to watch 'Shooter', but then Maccy remembered that Football Manager (Champ Manager) Live starts today, so he went on that instead.

I checked deviantArt and hotUKdeals and bought a 3DVD dance instructions set so I can be like Napoleon Dynamite (actually I'm probably too busy to watch it, but will have it to watch maybe in a year or sumat). Then I went on ebay to check if they had any cheap Manfrotto 682s or 681s. They didn't, and when they do they normally sell for about the same as the Buy it now ones on there anyway (about £67 + £7P&P).

So I went on warehouse express and bought the 682B from there. I had a look to see if they had anything I might want since P&P is £8, so it would be a good idea to order anything else at the same time as the monopod. I specifically looked for a right-angle surveyor's style bubble level (attaches on to the leg of a monopod, useful where you are holding the monopod above your waist) and also a diffusion materials pack like this one that John K said was good. They didn't have either of those or anything else I could see interesting for a reasonable price (in their clearance section, a lot of the items 'special price's were higher than the 'normal price'. Before checking out I noticed that on their homepage there was a notice saying 'Free shipping on orders over £50 until Christmas', so I'm glad I didn't order it the other day, and it makes it quite a bit cheaper than ebay (and anywhere else) now.

I watched Maccy go on FM Live for a bit, then checked the dpreview canon lens forum, then went to bed.

Food
Breakfast: Crunchy nut cornflakes; orange juice.
Lunch: Beef with mustard, sliced cherry tomatoes and baby leaf salad sandwich; tangerine; slice of home-made jam sponge cake; caramel Rocky; cup o' tea.
Dinner: Nasi Goreng; Noodles. Pudding was Jamaica Ginger cake with golden syrup and custard. Coffee; Roses.

No comments: