[Pro] Javascript for Search Field, Safari problems

Walter,

Altering the code as you suggest certainly resolves the dual-onload conflict, but it creates a new problem too. Here’s my modified code, as per your advice:

//clear & unselect search field on page load
document.addEventListener('load',function(evt){
 var GF = document.getElementById("Field");
 //delete field contents and defocus on page load
 GF.value = "";
 GF.blur();
 //delete field contents and defocus when user clicks outside field
 GF.addEventListener("blur", function COF() {GF.value = '';});
}

The problem that results is that the closing line in the code above no longer works to clear the contents of the field when the user clicks outside the field. In other words…

This part of the code still works fine…

 GF.value = "";
 GF.blur();

But this line no longer works at all…

 GF.addEventListener("blur", function COF() {GF.value = '';});

I tried moving that last line outside the function, as follows, but it still doesn’t clear the field contents when the user clicks outside the field:

//clear & unselect search field on page load
document.addEventListener("load",function(evt){
 var GF = document.getElementById("Field");
 //delete field contents and defocus on page load
 GF.value = "";
 GF.blur();
});

//delete field contents and defocus when user clicks outside field
document.getElementById("Field").addEventListener("blur", function(evt){
    document.getElementById("Field").value = '';
});

I tried this variation, but it does not work either…

//delete field contents and defocus when user clicks outside field
document.addEventListener("blur", function(evt){
    document.getElementById("Field").value = '';
});

Changing “document” to “window” does not resolve the problem either. Before, when I used “window.onload” it worked fine to clear the field contents when the user clicked outside the field.

Any idea what I am missing?

Thanks,

James W.


dynamo mailing list
email@hidden
Update your subscriptions at: