How to get update all hidden fields with same name?

I have multiple hidden field with same name on html page like below

    <input type="hidden" name="customerID" value="aa190809" />

I need to update values of all hidden field with same name i.e. customerID

I know how to do it(through Jquery) if html page contains single hidden field with customerID like below but not sure if there are multiple hidden field with same name

            if(updatedCsrf !== null) {
                var customerIDHidden = $("input[name='customerID']");
                if(customerIDHidden !== null) {
                    customerID.val("some_value");
                }
            }

Answers 1

  • Use jQuery each function

    $("input[name='customerID']").each(function(){
        $(this).val("some-value");
    });
    

Related Articles