How to assign the value of a variable that is in a JavaScript function to an SQL query.

3

I have a javascript function that gets the value of the selected item in a combobox, and would like to pass that value as a parameter to a SQL query to bring the data that are related to the value obtained in the selected combobox in my asp page, follows my javascript function and my SQL query.

function obterOpcaoSelecionada(){
//obter o elemento select
var formu = frmDados.cb_catinsumo.value;

//obter o índice da opção selecionada
var indiceSelecionada = elem.options.selectedIndex;
}

SQL code:

    SELECT 
    id_insumo,nome_comercial 
FROM 
    tb_insumo
WHERE 
    id_catinsumo = 
            (   SELECT 
                    id_catinsumo as id
                FROM
                    tb_catinsumo
                WHERE
                    categoria_insumo ='parametroJavaScritp' 
            ) 
ORDER BY 
    nome_comercial 
    
asked by anonymous 24.04.2014 / 19:37

1 answer

2

You can use jQuery.ajax() to perform this procedure.

Example

var request = $.ajax({
    url: "pagina_que_fara_a_consulta.php",
    type: "POST",
    data: { sua_variavel : conteudo },
    dataType: "html"
});

request.fail(function( jqXHR, textStatus ) {
    alert( "Request failed: " + textStatus );
});

See more at link

    
24.04.2014 / 20:33