Change hidden input value

60 views Asked by At

I want change hidden input value from other input value.

This is code:

 $(document).ready(function() {
$(\'input:text[name="'.$data['name'].'"]\').keyup(function() {
 $(\'input:hidden[id="'.$data['name'].'"]\').val( "'.$data['id'].'," + $(this).val() );
});
 });

This code work but i don't know how to change from keyup to always set value even if he does not edit the field and the field contains data from the database If I don't edit the field, it won't load anything into the hidden field

I entered various functions in various ways and nothing

1

There are 1 answers

2
Rustamjon Akhmedov On

try to use following code , it changes the value of input:text when input:hidden value changes.

$(document).ready(function() {
        // this part handles when input:text field changes value 
            $('input:text[name="' + $data['name'] + '"]').on('input', function() {
                $('input:hidden[id="' + $data['name'] + '"]').val($data['id'] + ',' + $(this).val());
              });

// this part handles when loading page , set value of hidden input by value of input:text value 
    let $textInput = $('input:text[name="' + $data['name'] + '"]');
        let $hiddenInput = $('input:hidden[id="' + $data['name'] + '"]');
   let $textval = $textInput.val();
      $hiddenInput.val($textval);
            });