To assign value to the input field after selecting item in Select

Asked

Viewed 640 times

0

I have a select field with a list of names, after selecting one of them I have to assign a value in the database to an input field.

Esquema

  • jquery or vanilla even?

  • "assign a bank value to an input field" - you can explain that part better?

  • you have to assign the value that was selected in the select field to input as well ? That’s it ?

  • Yes. I have to sweep the bank (select * from bank')

  • in the input field I have to assign this value!

  • Good if it is as I think, with javascript this is solved, because as you select the value within select it fills the input field you need with that respective value

  • some example, step-by-step or case study ?

  • I created an answer to this, if you attend me a feedback marking as best response

  • You want to search by name or by some name code?

  • See if this link helps: https://answall.com/q/14646/66203

Show 6 more comments

1 answer

1


From what I understand you want to catch the value of your field select and play for a field input if it’s not that, comment that I edit the answer to suit better

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script type="text/javascript">
        $(document).on('change', '.get-placa', function () {
            var value = $(this).val();
            $('.close').trigger('click');
            $('.campo2').val(value);
        });
</script>

<div class="col-lg-3">
    <select class="form-control get-placa" type="text"  name="campo1" maxlength='4'>
        <option></option>
        <option value='Campo1'>Campo1</option>
        <option value='Campo2'>Campo2</option>
    </select>
</div>

<div class="col-lg-3">
    <label for="ex1">Pegando Value do Select:</label>
    <input type="text" class="form-control campo2" maxlength="14"  name="campo2"><br><!-- Input CNPJ -->
</div>

  • take the value of your select field and play for an input field, that’s right...!

Browser other questions tagged

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