Skip to content

Instantly share code, notes, and snippets.

@mayank
Forked from mazjs/form.js
Last active September 8, 2015 07:56
Show Gist options
  • Select an option

  • Save mayank/9227034ed9ce93c24366 to your computer and use it in GitHub Desktop.

Select an option

Save mayank/9227034ed9ce93c24366 to your computer and use it in GitHub Desktop.
//the whole thing is wrapped in an anonymous function
$(document).on('change', '#id_tel_no', function() {
var tel_no = $('#id_tel_no').val();
var state_code = $('select[name=state_code]').val();
var customer_id = '<?php echo $customer->id;?>';
if (state_code != '' && tel_no != '') {
$.ajax({
type:"POST",
timeout:AJAX_TIMEOUT,
async: false,
data: {state_code: state_code, tel_no: tel_no, customer_id: customer_id},
url:"", //took out url for security reason
success: function( data ) {
if (data.result != null) {
$('#id_tel_no').focus();
dialog('Warning', data.result, DIALOG_WIDTH_WARNING_MESSAGE);
}else{
return true;
}
}
});
}
});
$("#id_customer_form").on('click', '#save', function(e) {
e.preventDefault();
var company_name = $('input:text[name=company_name]').val();
var country_code = $('#id_country_code').val();
var excluded_company_name = $('#id_excluded_company_name').val();
var customer_id = '<?php echo $customer->id;?>';
var edit = <?php echo isset($edit) && $edit ? $edit : 'false'; ?>;
unsaved = false;
if( ! edit || ! company_name_unique) {
$.ajax({
type:"POST",
timeout:AJAX_TIMEOUT,
async: false,
data: {company_name: company_name, country_code: country_code, excluded_company_name: excluded_company_name, customer_id: customer_id},
url:"", //took out url for security reason
success: function( data ) {
if (data.success) {
$('#id_customer_form').submit();
} else {
company_name_unique = false;
}
}
});
} else {
$('#id_customer_form').submit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment