I have a code where I will need to have a processing page, and on this page I will need to execute a javascript function automatically.
Currently, I execute this function by clicking, like this:
<input type="button" id="listarFipe" value="Listar Veiculos Fipe" />
My role:
$(function() {
$('#listarFipe').click(function() {
var categorias = new Array();
var carros = new Array();
var potencia = new Array();
var valvulas = new Array();
var filtroMotor = new Array();
var filtroValvula = new Array();
//select montadora
mont = document.form.montadora.selectedIndex;
montadora = document.form.montadora[mont].value;
AnoI = document.form.AnoInicial.selectedIndex;
AnoInicial = document.form.AnoInicial[AnoI].value;
AnoF = document.form.AnoFinal.selectedIndex;
AnoFinal = document.form.AnoFinal[AnoF].value;
//alert(j);
$('input[id=montadora]:checked').each(function() {
categorias.push($(this).val());
});
$('input[id=veiculo]:checked').each(function() {
carros.push($(this).attr('class'));
});
$('input[id=potencias]:checked').each(function() {
potencia.push($(this).attr('class'));
});
$('input[id=valvulas]:checked').each(function() {
valvulas.push($(this).attr('class'));
});
$('input[id=filtroMotor]:checked').each(function() {
filtroMotor.push($(this).val());
});
$('input[id=filtroValvula]:checked').each(function() {
filtroValvula.push($(this).val());
});
//alert('getModeloFipe.php?montadora='+montadora+'&veiculos='+carros+'&motor='+potencia+'&valvulas='+valvulas+'&anoini='+AnoInicial+'&anofim='+AnoFinal+'&filtroMotor='+filtroMotor+'&filtroValvula='+filtroValvula);
var url='getModeloFipe.php?montadora='+montadora+'&veiculos='+carros+'&motor='+potencia+'&valvulas='+valvulas+'&anoini='+AnoInicial+'&anofim='+AnoFinal+'&filtroMotor='+filtroMotor+'&filtroValvula='+filtroValvula;
/*
var url ='getModeloFipe.php?montadora='+montadora+'&veiculos='+carros+'&motor='+potencia+'&valvulas='+valvulas+'&AnoInicial='+AnoInicial+'&AnoFinal='AnoFinal;
*/
//enviar para url ajax
$.get(url, function(dataReturn) {
$('#checkVeiculosFipe').html(dataReturn);
});
});
});
I tested a possible solution I found on the net:
$( "#assinar" ).trigger( "click" );
Or change your javascript function from the click:
$("#assinar").click(function(){
...
To:
function processaAssinar() {
...
and call the function processaAssinar()
soon after it finishes its processing.