CF7 change input value on onChange using jQuery

This example explains how to get a value with jQuery from a select and set another input value dynamically


    how many participants?

    0 meat 0 fish

    <p><span>how many participants?</span>[select menu-811 id:participants include_blank "1" "2" "3" "4" "5" "6" "7"]</p>
    <p><span id="meatcount">0</span> meat [range* your-fishmeat id:fishmeat min:0 max:7 step:1 "0"]<span id="fishcount">0</span> fish </p>
    <p class="submitForm">[submit "Submit"]</p>
    <script type="text/javascript">
        function updateFishMeat() {
    // selected value 
          if (!$('#participants').val()) return 0;
          $('#fishmeat').attr( 'max', $('#participants').val() );
          $('#fishcount').text( $('#fishmeat').val() );
          $('#meatcount').text( $("#fishmeat").attr('max') - $('#fishmeat').val() );
        $('#participants').change( updateFishMeat );
        $('#fishmeat').change( updateFishMeat );

    Post navigation

    You might be interested in...

    No comments yet, be the first!


    Your email address will not be published. Required fields are marked *