0

I got a requirement to send the search text to GTM for tracking purpose. I have a field which is from search api autocomplete module. I am not getting the value in jQuery on click of submit button. I tried like below but no success:

var search_key = $('.path-frontpage .ui-autocomplete-input').attr('value');

Can anybody implemented such thing. Please help

DOM:

<input placeholder="Search MyP&amp;O" data-drupal-selector="edit-keywords" data-search-api-autocomplete-search="search" class="form-autocomplete form-text form-control ui-autocomplete-input" data-autocomplete-path="/search_api_autocomplete/search?display=page&amp;&amp;filter=keywords" type="text" id="edit-keywords" name="keywords" value="" size="30" maxlength="128" autocomplete="off">
  • An obvious thing, but in your selector you've got .path-frontpage which will obviously only work when on the homepage. Are you definitely trying on your homepage? – Leigh Sep 16 at 10:38
  • Yes @Leigh. i'm trying there only. – Suraj Sep 16 at 10:52
0

This works for me:

var search_key = $('.path-frontpage .ui-autocomplete-input').val();
  • thanks for responding. But for me its showing empty value. I will post my DOM structure. Please check. – Suraj Sep 16 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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