Home Automatically update a form field based on input in another field (only got name)
Reply: 0

Automatically update a form field based on input in another field (only got name)

user1513
1#
user1513 Published in April 26, 2018, 1:47 pm

I'm a complete beginner, so after several hours of pasting working scripts into my WP setup without any result, I turn to help. I'm desperate and out of time :(

I'm trying to update a form field based on the input of another form field (first is a select menu, second is a regular text-input). It's a Wordpress / Woocommerce installation with the fields generated by a plugin so I can't control the output. The fields only have names (no IDs) and all examples I find use IDs.

Form code

<select class="addon addon-select" name="addon-8-choose-a-player-0">

                <option value="">None</option>

                <option data-raw-price="200" data-price="200" value="player-1-1">Player 1</option>
                <option data-raw-price="200" data-price="200" value="player-2-2">Player 2</option>
                <option data-raw-price="200" data-price="200" value="player-3-3">player 2</option>

</select>

<input type="text" class="input-text addon addon-custom" data-raw-price="100" data-price="100" name="addon-8-name-100-1[0]" value="">

jQuery code

jQuery(document).ready(function( $ ) {

    function onchange() {
        var box1 = $("select[name='addon-8-choose-a-player-0]");
        var box2 = $("#addon-8-name-100-1[0]");
        box2.val(box1.val());
    }
    $("select[name='addon-8-choose-a-player-0]").on('change', onchange);
});
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.516568 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO