<script language=javascript>
// magic by RPIOLA (roberto@ilpiola.it) 20100210
// since microsoft search server's advanced search,
// if you do have a scope selector and you do not select
// any of the scopes, performs a global search,
// this javascript, inserted into a hidden webpart
// on advanced.aspx, intercepts the form submit action,
// verifies if there is at least one checkbox ticked and,
// if none is found, ticks the first one, or the first N
// it finds. please configure into the global declaration
// global_ntocheck the number of the scopes you want to use
// as a default
global_ntockeck=8;
function my_onsubmit()
{
var myresult='here comes the magic';
var i;
var thefirstone=-1;
var onechecked=false;
for(i=0; i<theForm.elements.length; i++)
{
if(theForm.elements[i].type=="checkbox")
{
if(thefirstone==-1)
thefirstone=i;
myresult=myresult+"; " + theForm.elements[i].name;
if(theForm.elements[i].checked)
onechecked=true;
}
}
if(!onechecked)
{
if(thefirstone==-1)
alert('you should tick at least one scope... but I didn\'t find any');
else
{
// alert('you should tick at least one scope... I assumed the first one');
theForm.elements[thefirstone].checked=true;
ntocheck=global_ntockeck-1;
for(i=thefirstone+1; i<theForm.elements.length && ntocheck>0; i++)
{
if(theForm.elements[i].type=="checkbox")
{
theForm.elements[i].checked=true;
ntocheck--;
}
}
}
}
return default_onsubmit();
}
default_onsubmit=WebForm_OnSubmit;
WebForm_OnSubmit=my_onsubmit;
</script>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)