Skip to content

Instantly share code, notes, and snippets.

@beau-gosse
Created January 7, 2016 18:42
Show Gist options
  • Save beau-gosse/e8aae6c83feb351b57b0 to your computer and use it in GitHub Desktop.
Save beau-gosse/e8aae6c83feb351b57b0 to your computer and use it in GitHub Desktop.
[MODX] Change Bible search landing page with JQuery via dropdown menu.
// # Change search action, update placeholders and dropdown menu texts
var radio = $('input[name="target"]');
radio.change(function(e) {
var form = $('#searchform'),
target = $("input[name=target]:checked"),
targetselect = $('#target_select'),
targetlabel = target.data('label'),
search = $('#search'),
caret = '<span class="caret"></span>',
version = $('#version'),
site = '[[++site_search_landing]]',
bible = '[[++bible_search_landing]]',
choice = this.value;
if (choice === 'bible') {
form.attr('action', bible);
search.attr('placeholder', 'Search in ' + targetlabel + ' Ex: Genesis 4:6');
} else {
form.attr('action', site);
search.attr('placeholder', 'Search in ' + targetlabel);
version.prop('disabled', true);
}
targetselect.html(targetlabel + ' ' + caret);
});
// Set default values for the search field placeholder and dropdown menu
$('#target_select').html($("input[name=target]:checked").data('label') + ' <span class="caret"></span>');
$("#search").attr('placeholder', 'Search in ' + $("input[name=target]:checked").data('label'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment