Forum Moderators: open

Message Too Old, No Replies

Merge 2 functions in to 1 so the one can be loaded with others, works!

Script works but not in the manner I want it to! ;-)

         

JAB Creations

9:17 pm on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok first off this is a full fledged already working script! So what I AM trying to do is to get this working in a different and more effective manner!

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>
<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>

[/dramaticmusic]

Bernard Marx

12:06 pm on Nov 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are using the onload event to call a function that attaches a function to the onload event. The onload event has already fired.