Morning spent tidying stuff up in anticipation of the engineer, who has of course not arrived as yet.
The afternoon has been spent faffing with javascript. Julie was tempted by the idea of randomized links, so I had a quick play, and have ended up with something workable.
So far I've only encountered two annoying things - lack of autocomplete meant I spent twenty minutes trying to work out what I was doing wrong before discovering that getElementByID should be getElementById, and I also discovered that editing the value of a textarea in a loop is a bad idea - putting together the string separately and then updating the textarea at the end is vastly faster.
I doubt I'll need javascript skills very often, but it's been fun to have a play around with it.
The afternoon has been spent faffing with javascript. Julie was tempted by the idea of randomized links, so I had a quick play, and have ended up with something workable.
So far I've only encountered two annoying things - lack of autocomplete meant I spent twenty minutes trying to work out what I was doing wrong before discovering that getElementByID should be getElementById, and I also discovered that editing the value of a textarea in a loop is a bad idea - putting together the string separately and then updating the textarea at the end is vastly faster.
I doubt I'll need javascript skills very often, but it's been fun to have a play around with it.
no subject
Date: 2010-02-25 02:53 pm (UTC)no subject
Date: 2010-02-25 02:59 pm (UTC)Nearly anything you want to do in JS is made 10 thousand times easier with JQ.
no subject
Date: 2010-02-25 03:24 pm (UTC)Total code:
body onload="setuprandom();"
and
function setuprandom()
{
var chosenLink = randomlinks[Math.floor(Math.random()*randomlinks.length)];
var randomElement = document.getElementById('random')
randomElement.href=chosenLink;
}
no subject
Date: 2010-02-25 04:05 pm (UTC)no subject
Date: 2010-02-25 05:59 pm (UTC)no subject
Date: 2010-02-25 09:31 pm (UTC)I see: Javascript prefers to retrieve elements via the deepest, unorganised part of its consciousness, rather than routing via Idaho.
no subject
Date: 2010-02-26 02:10 am (UTC)And its much easier to explain to an ethics committee "oh, the computer just does it" :D
no subject
Date: 2010-02-26 07:27 am (UTC)Instead of having to put an onload (which isn't reliable if you have images btw, but not your case here), you just start your JQ off with:
$('document').ready(
// everything goes here
);
and you can also say:
$('#random').href = chosenLink; // or somesuch IIRC, pre-breakfast
The beauty of JQ is it all works with CSS selectors. Oh and it's an object-chaining pattern, so it's $(get JQ).do().another().andsomemore().
no subject
Date: 2010-02-26 07:34 am (UTC)no subject
Date: 2010-02-26 08:49 am (UTC)Next time I'm playing with JS I'll give it a look!
no subject
Date: 2010-02-26 11:51 am (UTC)no subject
Date: 2010-02-26 02:25 pm (UTC)