Search code examples
javascriptphpjqueryformshidden-field

Place values to hidden field using JQuery/Javascript


I'm trying to place a data to a hidden field using JQuery, I want to place a text to the field "fieldName" with custom values, but I don't know how to pass the text to the field using jQuery.

The code that I used is:

$('span.open-apply-modal').click(function(){
    $('#apply-modal, #modal-backdrop').fadeIn(150);

});

The field is inside the div apply-modal.

I want to place the value "Accountant" to the hidden field after the FadeIn(150) is called. How do I do that?


Solution

  • Try:

    $('span.open-apply-modal').click(function(){
        $('#apply-modal, #modal-backdrop').fadeIn(150);
        $("#hidden_field_id").val('Accountant');
    });
    

    To put the value after the fade is executed try this:

    $('#apply-modal, #modal-backdrop').fadeIn(150, function(){
        $("#hidden_field_id").val('Accountant');
    });