Unfortunately as I concluded, If you want to work with two search-box in a sharepoint page (for example one in the layout page and other in the master page/ or simply add two sharepoint search box web parts to a webpart zone. all of the search boxes have a div element with same id (id="SearchBox"
) and this make some misfunctions (for example all the search box automaticly get the value which you type in one of them). What is the solution for this situation? Is it logically wrong to add more than one search-box in a page? Thanks in advance.
-
I believe one possible solution for this is to use jQuery to identify your inputs and then you can add on a class or append the ID's. I do not have the exact code but jQuery may be your best approach here.– klip28Jun 21, 2019 at 17:43
1 Answer
Try this jQuery code, it will find all inputs that contain and ID with "Search*", create a 0 value and then add 1 and then change the ID so you can individualize it
$(document).ready(function(){
var counter = 0;
$('input[id*="Search"]').each(function(){
var currentID = $(this).attr('id')
$(this).attr('id', currentID + counter)
counter++
});
});