M
M
mipfikus2020-06-30 15:13:32
WordPress
mipfikus, 2020-06-30 15:13:32

Why doesn't the JS code inside the form work?

I need to change the text in the contact form from the Contact Form 7 plugin, depending on the language, to the desired language.
This is how the JS turned out:

spoiler
var getLangCode = 'lv'; // Упрощенный вид кода
if(getLangCode == "lv")
  {
    document.getElementById('cf7-form-text').value='Jūsu vārds';
    document.getElementById('cf7-form-telefon').value='Jūsu tālrunis';
  }
But the text of the contact form in the pop-up window has not changed (it is inside the "Buy in 1 click" button):
spoiler
5efb2c484c75b437280343.png
Page example: mextra.segmenti.lv/lv/product/dimanta-urbsanas-iekarta-weka-32/ I checked
in other places, the code is working.
Popup makes plugin Art Buy in One Click Woocommerce

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-07-01
@mipfikus

The reasons may be different...
1) Exclude the presence of any js errors in the browser console related or not related to this code.
2) See if the getLangCode variable is set to the correct value. How exactly on the client do you get the value of the language variable? You can also change the text on the server side. Do you have a wpml plugin? And here's how to check the current language

<?php if ( ICL_LANGUAGE_CODE=='lv' ) : ?>
//code
<?php endif; ?>

3) I am concerned about the issue of the trigger. If you are using vanilla js then try wrapping your code in
document.addEventListener("DOMContentLoaded", function() {
  // код
});

and see if your snippet works.
In general, you need to debug the code and see where and what does not work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question