Skip to content

Instantly share code, notes, and snippets.

@NightZpy
Created October 30, 2014 20:41
Show Gist options
  • Save NightZpy/145b151a601d038f44a8 to your computer and use it in GitHub Desktop.
Save NightZpy/145b151a601d038f44a8 to your computer and use it in GitHub Desktop.
jQuery( document ).ready(function() {
jQuery('#marca').click(function(){
jQuery.post('list.php', { type: "descripcion", id: jQuery('#marca').val()},
function(response){
jQuery('#descripcion').html('');
jQuery('#descripcion').append('<option value=\"\">-- Seleccione --</option>');
response = jQuery.parseJSON(response);
jQuery.each(response, function (k,v){
jQuery('#descripcion').append('<option value=\"'+v.descripcion+'\">'+v.descripcion+'</option>');
});
jQuery("#descripcion").removeAttr('disabled');
});
});
/*jQuery('#anio').click(function(){
jQuery.post('list.php', { type: "anio", marca: jQuery('#marca').val(), descripcion: jQuery('#descripcion').val(), anio: jQuery('#anio').val()},
function(response){
response = jQuery.parseJSON(response);
if(response[0].cotizacion >= 0) {
}
});
});*/
var $params = {debug:false, rules:{}, messages: {}};
var $anio = jQuery("#anio").attr("name");
var $marca = jQuery("#marca").attr("name");
var $descripcion = jQuery("#descripcion").attr("name");
var $codigoPostal = jQuery("#codigo_postal").attr("name");
$params['rules'][$marca] = {"required": true};
$params['rules'][$descripcion] = {"required": true};
$params['rules'][$anio] = {"required": true, "digits": true, "maxlength": 4, "minlength": 4};
$params['rules'][$codigoPostal] = {"required": true, "digits": true, "maxlength": 5, "minlength": 5};
jQuery("#formCotizar").validate($params);
/*jQuery("#formCotizar").ajaxSubmit({
success: function(response){
jQuery.fancybox({
'content' : response
});
}
}); */
var options = {
//target: '#output2', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
};
jQuery("#formCotizar").ajaxForm(options);
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
setTimeout(jQuery.fancybox({
'content': "<h1>Calculando cotización</h1><img src='./images/loader.gif' alt='Cargando'>",
'autoScale' : true,
'transitionIn' : 'none',
'transitionOut' : 'none',
'scrolling' : 'no',
'type' : 'inline',
'showCloseButton' : false,
'hideOnOverlayClick' : false,
'hideOnContentClick' : false
})
, 5000 );
return jQuery("#formCotizar").valid();
}
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
jQuery.fancybox({
'content' : responseText,
'autoScale' : true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment