Set default value of field to another field already entered

Support MB Builder Set default value of field to another field already entered

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9586
    WendellWendell
    Participant

    I'm building an events system. I have a metabox with fields for Start Date and End Date. When a user adds a Start Date, I would like the End Date field to automatically default to the same date entered into the Start Date field.

    How can I accomplish this?

    #9592
    Anh TranAnh Tran
    Keymaster

    Hello,

    This can be done with custom JavaScript. Here is the pseudo-code:

    First step: enqueue your JS file:

    add_action( 'rwmb_enqueue_scripts', function() {
        wp_enqueue_script( 'your-js-id', 'url-to-your-js', ['jquery'], '', true );
    } );

    And in your JS file:

    jQuery(function(){
        var $start = $( '#start_date' ),
            $end = $( '#end_date' );
        $start.datepicker( {
            onSelect: function( dateText ) {
                $end.val( dateText );
            }
        } );
    });
    #10130
    WendellWendell
    Participant

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Set default value of field to another field already entered’ is closed to new replies.