Probably easy javascript question
Posted: Tue Oct 02, 2007 8:35 pm
Pretty simple, but my js knowledge is lame
If you click in the Search Tutorials box at the top of the homepage you will notice it removes the text so you can start typing. Problem is this only happens after the page has loaded.
I want this to happen instantly, or be loaded before the content basically.
Here is the script:
And it's being referenced in the index like this (fixed):
Any ideas? Cheers
If you click in the Search Tutorials box at the top of the homepage you will notice it removes the text so you can start typing. Problem is this only happens after the page has loaded.
I want this to happen instantly, or be loaded before the content basically.
Here is the script:
- Code: Select all
addEvent(window, 'load', init, false);
function init() {
var formInputs = document.getElementsByTagName('input');
for (var i = 0; i < formInputs.length; i++) {
var theInput = formInputs[i];
if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {
/* Add event handlers */
addEvent(theInput, 'focus', clearDefaultText, false);
addEvent(theInput, 'blur', replaceDefaultText, false);
/* Save the current value */
if (theInput.value != '') {
theInput.defaultText = theInput.value;
}
}
}
}
function clearDefaultText(e) {
var target = window.event ? window.event.srcElement : e ? e.target : null;
if (!target) return;
if (target.value == target.defaultText) {
target.value = '';
}
}
function replaceDefaultText(e) {
var target = window.event ? window.event.srcElement : e ? e.target : null;
if (!target) return;
if (target.value == '' && target.defaultText) {
target.value = target.defaultText;
}
}
And it's being referenced in the index like this (fixed):
- Code: Select all
<input type="text" class="searchField cleardefault" name="search" value="Search Tutorials" />
Any ideas? Cheers