2
I have a code where I will need to have a processing page, and on this page I will need to run a javascript Function automatically.
Currently, I run this Function by clicking, like this:
<input type="button" id="listarFipe" value="Listar Veiculos Fipe" />
my job:
$(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 click function from:
$("#assinar").click(function(){
...
To:
function processaAssinar() {
...
and call the function processaAssinar()
right after you finish your processing.
You mean you want to run that anonymous function that the click makes run, but when the page loads and without being dependent on a click?
– Sergio
yes correct, this function is on a registration edit page, I need it to be loaded automatically
– luis ricardo
So just remove
$('#listarFipe').click(
and the last)
just staying:function processaAssinar() {
instead of$('#listarFipe').click(function() {
. You already tested that?– Sergio
Put the code you made in jsFiddle. I don’t see it in your comment...
– Sergio
I had already tested, but I tested again getting like this: <pre>Function listarFipe() { </pre> and tested like this also <pre>$(Function() { Function listarFipe() {</pre> I need to put this function to automatically load on the page, not needing to click to call it
– luis ricardo
http://jsfiddle.net/inforicky/u7qhf6ra/
– luis ricardo
Okay, so just run/call the function... joining
listarFipe();
at the end. -> http://jsfiddle.net/u7qhf6ra/1/– Sergio
You have the option to exchange your Function for $(Document). ready(Function(){...}). Function will be executed as soon as the document is loaded
– Thomas Lima
Doubt solved
– luis ricardo