Forum Moderators: open
There are two functions (addevent and searchfocus). I need to take the addevent code (required for the searchfocus function to work) and merge it in to the same function (we'll keep searchfocus as the focus).
The goal is to load searchfocus via onload with other onload functions. Alone it works fine but once other functions are added (multiple onload function code is currently commented out) the focus does not work!
I tried to load the addevent function as well but nothing happened.
Somewhere I got "obj has no properties" in the Firefox JavaScript console. It's absolutely imperative to not have any errors in the JavaScript console (as this will ultimately be served as application/xhtml+xml and will thus break.
So I think the solution is to somehow merge the two functions together as searchfunction is dependent on addevent...but obj has no properties and the script not working when other onload functions are loading is the problem. Anyone want to take a crack at it? :)
The code [dramaticmusic]
<html>[/dramaticmusic]
<head>
<title>Focus</title>
<script type="text/javascript">
<!--
//
// Search Focus
//function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}function searchfocus()
{
addEvent(window, 'load', function() { document.getElementById('query_string').focus()});
}window.onload = searchfocus();
//
// make onload commented above to in order to use multiple onload code below so uncomment below afterwards
//
// window.onload = function() {
// detectid();
// searchfocus();
// target();
// };//-->
</script>
</head><body>
<form action="" class="search" id="search" method="post">
<fieldset>
<input type="hidden" name="path" value="" />
<input type="hidden" name="refine" value="0" />
<input type="hidden" name="result_page" value="" />
<label class="search" for="query_string">Search Site</label>
<input id="query_string" maxlength="50" name="query_string" size="9" onfocus="javascript:if(this.value=='Search...') {this.value='';}" onblur="javascript:if(this.value=='') {this.value='Search...'}" tabindex="1" type="text" value="Search..." />
<input class="button" type="submit" value="Search" />
</fieldset>
</form></body>
</html>