Reply To: Add a default search text(item) in the search box

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Add a default search text(item) in the search box Reply To: Add a default search text(item) in the search box

#5365

Ernest Marcinko
Keymaster

Hi!

I'm assuming you use multiple instances. Every search bar instance has a unique ID. The ID format is like this:

ajaxsearchpro{instance_ID}_{occurence_number}

As you can see there are 2 numbers, one identifiing the instance and the other tells how many times this search instance is placed on the same page.
So for example if the first instance is used once, then it's ID is going to be this:

ajaxsearchpro1_1

If you use this instance again on the same page (the same shortcode twice), then it's going to be:

ajaxsearchpro1_2

Same is true for the results and the settings container as well:

ajaxsearchprosettings1_1

and

ajaxsearchprores1_1

Now, if you want to target every occurence of the first instance, you can use this:

jQuery(function($) {
    var text = 'default text';

    $("div[id*='ajaxsearchpro1_'] input.orig").val(text);
});

To target only the first occurence of the first instance:

jQuery(function($) {
    var text = 'default text';

    $("#ajaxsearchpro1_1 input.orig").val(text);
});

Same way you can target the settings container:

$(“div[id*='ajaxsearchprosettings1_'] “) ….

or only the first occurence:

$(“#ajaxsearchprosettings1_1”) ….

Please note that these are advanced uses of jQuery and CSS. To understand how all this works you should definitely google “jQuery basics” and “CSS selectors” for more detailed explanation.

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)