The values ​​inserted with jquery are not submitted as

advertisements

I have a modal with a form:

<div class="modal-body">
    <form role="form" class="form-horizontal" action="../system/file_change.php" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <div class="col-sm-10">
                <input type="file" name="fileToUpload" id="fileToUpload">
            </div>
            <div class="col-sm-2">
                <input type="submit" name="submit" class="btn btn-info pull-right replacefile" value="<?php echo $data['text_replace']?>">
            </div>
            <input type="hidden" name="order_id" value="<?php echo $order_id; ?>">
            <input name="old_code" type="hidden" id="old_code">
            <input type="hidden" name="token" value="<?php echo $token; ?>">
        </div>
    </form>
</div>

And a script, which dinamycally insert a value to input name="old_code" field:

<script>
$('.replacefile').on('click', function(){
    $('#old_code').val($(this).attr('data-id'));
    console.log( $('#old_code').attr('value'));
});
</script>

console log gives back the correct code. My question is, why this code is not submitted with form? And how can i solve this problem?


Try this one:

<script>
$('.replacefile').on('click', function(){
    $('#old_code').val($(this).val());
    console.log( $('#old_code').val());
});
</script>