Call function by OnClick passing parameters

-1

I'm trying to call a function by clicking on a link, where a parameter is passed that will be used in an Ajax request.

This request will return results that will be added to a div.

The link code for the function call is as follows:

<a href="javascript:;" id="Iniciais" onclick="pBuscaFichaEmergencia('<?php echo $Letra; ?>');"><?php echo $Letra; ?></a>

The function code is:

function pBuscaFichaEmergencia(){
    var Iniciais = $('#Iniciais').val(); 

    console.log("INICIAL: " + Iniciais);

    if (Iniciais) {
        var url = 'pBuscaFichasLetras.php?Iniciais='+Iniciais 
        $.get(url, function(dataReturn) {
            $('#resp-emergencia').html(dataReturn);  
        });
    }
}
    
asked by anonymous 26.12.2016 / 14:29

1 answer

2

If you will pass the letters through PHP in this way

<a href="javascript:;" id="Iniciais"  onclick="pBuscaFichaEmergencia('<?php echo $Letra; ?>');"> <?php echo $Letra; ?>  </a>

You need to declare your function by getting a parameter

function pBuscaFichaEmergencia(Iniciais )

And you will not need to use jquery to get the value

    
26.12.2016 / 14:39