Category: Code

  • BBC Homepage Beta Using jQuery

    The BBC Beta Homepage is using jQuery, but unfortunately it’s ugly. I should qualify that – I think it’s a good move to make the homepage more personalisable, but does it have to look so Web2.0? Big text was a fad a year ago, but it’s too informal for an internationally recognised and respected news…

  • JavaScript Bug – Modulo of small numbers

    It seems that there is a problem with the modulo function, ‘%’, in JavaScript. For example: 10 % 0.1 should equate to zero but comes out as 0.09999999999999945 probably due to some internal floating-point rounding errors. Easy solution (a hack really): Multiply both numbers by 1000 before using the modulo function.

  • JS: Clear Default Value onFocus

    Simply add the following to the the onFocus attribute of any HTML form input tag. if (this.value == this.defaultValue) this.value = ”; this.defaultValue is automatically given the value in the HTML.

  • Append to Body onLoad

    I looked for a long time how I could add JavaScript functions to an HTML document’s onLoad attribute. Eventually I found this, something so obvious that I had considered trying it but foolishly didn’t try.

  • jsReq

    I wanted to tell the user that they need JavaScript, but obviously only if they don’t already have it enabled.The following is a very crude script which uses the very fact that JS is available to hide the requirement notice… HTML: JS: