简体   繁体   English

在 Elementor 弹出窗口中填写输入字段

[英]Fill input field in Elementor pop-up

I am trying to create a function which would fill input in popup window automatically depending on brn id that was clicked.我正在尝试创建一个 function ,它将根据单击的 brn id 自动填充弹出窗口 window 中的输入。

This is where I am at:这就是我所在的位置:

const btn = document.querySelector('.popup-activator')
let btnId

btn.addEventListener('click', function(){
   btnId = this.id;
});
document.getElementById("form-field-id").value = btnId; 

I can see that my id is saved in btnId, but it's not showing up in form field.我可以看到我的 id 保存在 btnId 中,但它没有显示在表单字段中。 It might be because when I click the button popup is not generated on the page yet, it opens after I click the button.这可能是因为当我单击按钮时,页面上尚未生成弹出窗口,单击按钮后它会打开。 Here is the link I am trying to do this https://www.avistech.cz/pujcovna-nakladace/ it's applied on first button 'Poptat'这是我正在尝试执行此操作的链接https://www.avistech.cz/pujcovna-nakladace/它应用于第一个按钮“Poptat”

If can anyone help I would really appriciate it如果有人可以帮助我真的很高兴

You need to assign the value to the input, when the modal is fully loaded.当模态完全加载时,您需要将值分配给输入。

const btns = document.querySelectorAll('.popup-activator')

btns.forEach(b => {
  b.addEventListener('click', function(){
    const btnId = this.id;
    // setting the value inside the fn so that it triggers after the button clicks
    // setTimeout delays the assignment a little so that the modal gets mounted
    setTimeout(() => {
      document.getElementById("form-field-id").value = btnId;
    })
  });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM