/    Sign up×
Community /Pin to ProfileBookmark

Trigger Problem

Hello,
I am working on WordPress (Woocommerce). There are 2 forms on the checkout page. After checking the chekbox, I am trying to transfer the data from the 2nd form to the first form. Texts are transmitted (eg shiping_adress —-> billing_address) There is no problem. However, I cannot transfer the select option instantaneously. It transfers after refreshing the page. However, I cannot see the change without renewal.
Also html : [Imagebb](https://i.ibb.co/1fgD1By/a023046.png)
As far as I can see it uses the woocommerce select2 library. I wrote a trigger but still couldn’t run it. Can you help me ?
My code’s:

“`
function add_checkout_script() { ?>
<script type=”text/javascript”>
jQuery(document).on(‘change’, ‘#copy_to_billing’, function() {
if(this.checked) {
jQuery(“[name=’billing_address_1′]”).val(jQuery(“[name=’shipping_address_1′]”).val());
jQuery(“[name=’billing_city’]”).filter(“:selected”).val(jQuery(“[name=’shipping_city’]”).filter(“:selected”).val());
jQuery(“[name=’billing_city’]”).trigger(“input”);
}
});

</script>
<input id=”copy_to_billing” type =”checkbox” name=”copy_to_billing”
value =”1″ class=”copy_billing woocommerce-form__input woocommerce-form__input-checkbox input-checkbox”><span><?php esc_html_e( ‘ send’, ‘woocommerce’ ); ?></span>
“`


to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumMay 02.2021 — You have to use the value of the select itself, not the selected option:
``<i>
</i> // jQuery("[name='billing_city']").filter(":selected").val(jQuery("[name='shipping_city']").filter(":selected").val());
jQuery("[name='billing_city']").val(jQuery("[name='shipping_city']").val());<i>
</i>
``
Copy linkTweet thisAlerts:
@wpdevelislauthorMay 24.2021 — @Sempervivum#1631097

I did not see this answer. Sorry. Thank you.
×

Success!

Help @wpdevelisl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...