Skip to content

Instantly share code, notes, and snippets.

@Joachimaus
Created September 10, 2019 01:27
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 Joachimaus/6a5e6e5a42cc8dee3b27d05f5fee2a07 to your computer and use it in GitHub Desktop.
Save Joachimaus/6a5e6e5a42cc8dee3b27d05f5fee2a07 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
function updateEmail() {
var postcode = $('#campaign_fields_zip').val();
if($.isNumeric(postcode) && postcode.length > 3 && postcode > 0) {
if ((postcode >= 2600 && postcode <= 2618) || (String(postcode).substring(0, 2) == '29')) {
var memberState = "ACT";
$('#destination_address').val("senator.katy.gallagher@aph.gov.au");
} else if (String(postcode).charAt(0) == '2') {
var memberState = "NSW";
$('#destination_address').val("senator.faruqi@aph.gov.au,senator.ayres@aph.gov.au,senator.keneally@aph.gov.au,senator.mcallister@aph.gov.au,senator.oneill@aph.gov.au,senator.sheldon@aph.gov.au");
} else if (String(postcode).charAt(0) == '3') {
var memberState = "VIC";
$('#destination_address').val("senator.dinatale@aph.gov.au,senator.rice@aph.gov.au,senator.carr@aph.gov.au,senator.ciccone@aph.gov.au,senator.kitching@aph.gov.au,senator.walsh@aph.gov.au");
} else if (String(postcode).charAt(0) == '4') {
var memberState = "QLD";
$('#destination_address').val("senator.waters@aph.gov.au,senator.chisholm@aph.gov.au,senator.green@aph.gov.au,senator.watt@aph.gov.au,senator.hanson@aph.gov.au,senator.roberts@aph.gov.au");
} else if (String(postcode).charAt(0) == '5') {
var memberState = "SA";
$('#destination_address').val("Senator.farrell@aph.gov.au,senator.hanson-young@aph.gov.au,senator.wong@aph.gov.au,senator.marielle.smith@aph.gov.au,senator.bernardi@aph.gov.au,senator.patrick@aph.gov.au,senator.gallacher@aph.gov.au,senator.griff@aph.gov.au");
} else if (String(postcode).charAt(0) == '6') {
var memberState = "WA";
$('#destination_address').val("senator.siewert@aph.gov.au,senator.steele-john@aph.gov.au,senator.dodson@aph.gov.au,senator.lines@aph.gov.au,senator.pratt@aph.gov.au,senator.sterle@aph.gov.au");
} else if (String(postcode).charAt(0) == '7') {
var memberState = "TAS";
$('#destination_address').val("senator.whish-wilson@aph.gov.au,senator.mckim@aph.gov.au,senator.bilyk@aph.gov.au,senator.carol.brown@aph.gov.au,senator.polley@aph.gov.au,senator.urquhart@aph.gov.au,senator.lambie@aph.gov.au");
} else if (String(postcode).charAt(0) == '8' || String(postcode).charAt(0) == '9' || String(postcode).charAt(0) == '0') {
var memberState = "NT";
$('#destination_address').val("Senator.McCarthy@aph.gov.au");
}
$('#electorate_message').html("<div class='small'>We'll send the message below to " + memberState + " Senators</div>");
appendSupporterName();
}
}
$(function(){
// Add '#electorate_message' div to the page
$('#campaign_fields_zip').closest('.row,.row-fluid').after('<div class="row row-fluid"><div class="col-md-12"><div id="electorate_message"></div></div></div>');
// Validate postcode on page load (in case user is recognised by NB and has a postcode saved)
updateEmail();
$('#campaign_fields_zip,[data-name="Postcode"],[data-name="ZIP Code"]').on('change keyup', function(){
updateEmail();
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment