change value on an input with val() and trigger(‘change’)

I have a list of button with for each a specific value, I would like to get one of these value when I click on the button then put this value into a specific input. I am using symfony and jquery to do it.
Here is my code:

The different button with specific value :

{% block body %}
<div class="row">
    <div class="col-sm-12">
        <div class="card-box ">
            <h2 class="m-t-0 header-title">{{ "Données traitement"|trans }}</h2>
            <div class="btn-group btn-group-lg" role="group" aria-label="...">
                {% for s in secteur %}
                    <button id="linkSecteur_{{ s.SecteurId }}" class="text-lg-left btn btn-link z-btn-secteur essai" data-id="{{ s.SecteurId }}">{{ s.LibLong }}</button>
                {% endfor  %}

The input where I want to put the value selected with the button:

        <form id="searchForm" class="form-horizontal search-form " role="form" action="{{ path('api_post', {id: odata_search}) }}" method="post">
            <div class="row">
                <div class="col-6 col-md-8">{{ form_row(form.Secteur) }}</div>

Here it the test that I try to fix :

var $searchFieldSecteur = $("#form_Secteur");

            $('#linkSecteur_02').on('click',function() {

               var long = $(this).val('hello');

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *