How do I create list that by clicking call the function by sending a value?

Asked

Viewed 51 times

1

I’m wearing a Select to pass values to a Javascript function.

When selected takes the value and based on that value the function I have here returns something.

I would like to exchange for a list of links that when clicking do the same thing.

That’s the code I got:

       <select id="linha" onclick="selectBus()">
            <option value="1">item1</option>
            <option value="2">item1</option> 
            <option value="3">item1</option>
        </select>

This already works with the Select, but would like to exchange for a list of links.

  • use the event onchange

1 answer

0

<select id="linha">
    <option value="1">item1</option>
    <option value="2">item1</option> 
    <option value="3">item1</option>
</select>

<script>
    $(function(){
        // ao selecionar um serviço abre o combo de tipo
        $('#linha').on('change', function () {
            // Recupera o value do option
            var LinhaID = $(this).val();
            // Após você pode chamar uma ou mais funções
            funcao01();
            funcao02(LinhaID);
        });
    });

    function funcao01(){ /* coloque seu código aqui*/ }
    function funcao02(id){
        alert('O value selecionado é: ' + id);
    }
</script>
  • Wilson, maybe I wasn’t so clear. Today I already have a Select working with Javascript on onclick, all blz!! But instead of using a Select I want to use <a href></a> that when clicking it runs my Javascript function. Thank you

  • see if this is it: <a href="javascript:void(0)" onclick="myFuncao();">clique</a>

  • hi Wilson, didn’t work

  • do the following, put the full HTML code and selectBus() to better analyze blz.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.