3
I have a javascript function that gets the value of the selected item in a combobox, and would like to pass this value as parameter to an SQL query to bring the data that is related to the value obtained in the combobox Selected on 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
Everton, you’ll have to use AJAX. Do you know how to use it? Either pure javascript or use a library like jQuery or Mootools?
– Sergio
@Sergio never used AJAX, it would be good to learn ,I’m using pure javascript, but I can use a jQuery library if applicable.
– Everton
You are using pure Asp or Asp.net?
– Marciano.Andrade
I am using pure Asp @Marciano.Andrade.
– Everton
What programming language are you using on Asp? You can use a 'hiddenfield' object and via javascript you fill this 'hiddenfield', reading it in codebehind. Example: I fill the 'hiddenfield' via javascript and in my C# code I read this 'hiddenfield' to search the database.
– Gustavuu
@Gustavuu was exactly what I was thinking, he does not need to create a [Webmethod] for this, following the way you said I believe to be the fastest
– Marciano.Andrade
@Marciano.Andrade I am using Vbscript on Asp.
– Everton