Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have developed a Employee Directory and got this javascript for criteria search. But I want to fetch all employees first and then apply criteria. How to set the value of "Fixed Query" of People Search Core Result webpart using javascript when I press the search button without giving any criteria.

 <script language="javascript">

  //function for enter on keyboard and apostrophes in search strings
 function txtWildPeopleFinder_KeyDown(e)
 {
  if (e.keyCode == 13 || e.keyCode==10)
   {
    e.returnValue=false;
    DoWildPeopleSearch();
    return false;
    }
    else
    return true;
    }

function escapestr(str)
{
 return str.replace("'","%22");
}


//staff search
function DoWildPeopleSearch()
{
 var firstname = escapestr(document.all["firstname"].value);
 var lastname = escapestr(document.all["lastname"].value);
 var url;
 //search on last name onnly (first name is empty)
 if(firstname == "")
 {
  url = "BankDirectory.aspx?k=LastName%3A" + lastname;
  window.location=url;
 return;
}
//search on first name only (last name is empty)
if(lastname == "")
 {
  url = "BankDirectory.aspx?k=FirstName%3A" + firstname;
  window.location=url;
  return;
  }
 //search on first and last
 url = "BankDirectory.aspx?k=lastname%3A" + lastname +
 "%20FirstName%3A" + firstname;
 window.location=url;
 return;
 }


 </script><table width="100%" id="StaffSearchTable" border="0" cellspacing="0"          
 cellpadding="4"><tbody><tr><td width="80" nowrap="nowrap">First Name:</td>
 <td width="100%"><input name="firstname" id="firstname"       
 onkeydown="txtWildPeopleFinder_KeyDown(event)" type="text" size="25" maxlength="55"/>       
 </td></tr>
 <tr><td width="80" nowrap="nowrap">Last Name:</td>  
     <td><input name="lastname" id="lastname"     
      onkeydown="txtWildPeopleFinder_KeyDown(event)" type="text" size="25" 
     maxlength="55"/> </td></tr>

     <tr><td></td>
      <td><input onclick="DoWildPeopleSearch()" type="button" value="Search"/></td></tr></tbody></table>   
     <p>Enter all or part of a name<br/>e.g. A will find all names beginning with A</p>
share|improve this question
add comment

1 Answer

You would need to edit the CoreSearchResults web part properties and use the "Append Text to Query", see here http://www.sharepointconfig.com/2011/05/how-to-create-a-simple-sharepoint-2010-people-directory/

This shall automatically trigger a query and still allow you to add your own Keywords.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.