Skip to content

Instantly share code, notes, and snippets.

@l2c2technologies
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l2c2technologies/c09b1cb57605c70addc7 to your computer and use it in GitHub Desktop.
Save l2c2technologies/c09b1cb57605c70addc7 to your computer and use it in GitHub Desktop.
jQuery snippet designed to allow repetitive entry of similar addresses for patrons in a Koha installation. Details of the use-case is provided at https://www.facebook.com/notes/l2c2-technologies/jquery-to-solve-a-third-world-village-schools-address-problem/779090322180203
$(document).ready(function(){
var address_data = {
'location0': 'Vill. Amtala',
'location1': 'Vill. Karunamoyee',
'location2': 'Vill. Phoolbagan',
'location3': 'Vill. Maniktala'
}
var address2_data = {
'location1': 'PO + PS Khatra'
}
var address_select = $('<select id="address_chooser" />');
var address2_select = $('<select id="address2_chooser" />');
for(var val in address_data) {
$('<option />', {value: val, text: address_data[val]}).appendTo(address_select);
}
for(var val in address2_data) {
$('<option />', {value: val, text: address2_data[val]}).appendTo(address2_select);
}
$('#memberentry_mainaddress #address').after('<span id="choose_address">&nbsp;or <strong>choose</strong></span>');
$('#memberentry_mainaddress #choose_address').after(address_select);
$('#memberentry_mainaddress #address2').after('<span id="choose_address2">&nbsp;or <strong>choose</strong></span>');
$('#memberentry_mainaddress #choose_address2').after(address2_select);
$( "#address_chooser" ).keyup(function () {
var address_val = "";
$( "#address_chooser option:selected" ).each(function() {
address_val += $( this ).text() + " ";
});
$( "#memberentry_mainaddress #address" ).val( address_val );
})
$( "#address_chooser" ).mouseup(function () {
var address_val = "";
$( "#address_chooser option:selected" ).each(function() {
address_val += $( this ).text() + " ";
});
$( "#memberentry_mainaddress #address" ).val( address_val );
})
.mouseup()
$( "#address2_chooser" ).keyup(function () {
var address2_val = "";
$( "#address2_chooser option:selected" ).each(function() {
address2_val += $( this ).text() + " ";
});
$( "#memberentry_mainaddress #address2" ).val( address2_val );
})
$( "#address2_chooser" ).mouseup(function () {
var address2_val = "";
$( "#address2_chooser option:selected" ).each(function() {
address2_val += $( this ).text() + " ";
});
$( "#memberentry_mainaddress #address2" ).val( address2_val );
})
.mouseup()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment