简体   繁体   English

从 Elementor Pro Form 获取输入字段值

[英]Get input field value from Elementor Pro Form

I created a form using Elementor Pro Form widget.我使用 Elementor Pro Form 小部件创建了一个表单。 Now I want to write some code and I need to get the value of the input fields from the Elementor Pro Form.现在我想编写一些代码,我需要从 Elementor Pro 表单中获取输入字段的值。 How can I do that?我怎样才能做到这一点?

Here is what I did:这是我所做的:

  1. Created a form with the Elementor Pro Form widget.使用 Elementor Pro Form 小部件创建了一个表单。 Fields: Email , Website URL .字段: Email网站 URL I added ID to both of them.我给他们两个都加了ID。

Email input field id: email Email 输入字段ID: email

Website URL input field ID: websiteurl网站URL 输入字段ID: websiteurl

Submit button ID: analysee提交按钮 ID: analysee

  1. Imported HTML widget to my page and tried to DOM the value of the Website URL input field.将 HTML 小部件导入我的页面并尝试对网站 URL 输入字段的值进行 DOM 处理。 I added an Event Listener to the button (that works).我向按钮添加了一个事件侦听器(有效)。 When the button is clicked it should alert the value of the Website URL input field.单击该按钮时,它应提醒网站 URL 输入字段的值。

When I do that I get the following error:当我这样做时,我收到以下错误:

Uncaught TypeError: Cannot read properties of null (reading 'value')
    at HTMLButtonElement.<anonymous>

Here is my code:这是我的代码:

<script>
    let analyse_dugme = document.getElementById("analysee");
    let website_url = document.getElementById("websiteurl");
    
    analyse_dugme.addEventListener("click", function(){
        alert(website_url.value);
    });
    
</script>

How can I solve this?我该如何解决这个问题?

Thank you for your time.感谢您的时间。

  1. You can use the val() property to retrieve the input's value, by doing something like this:您可以使用 val() 属性来检索输入的值,方法如下:

     jQuery(document).ready(function($) { $('#theForm').submit(function() { // #theForm to select the whole form let analyse_dugme = $("#email").val(); // get the email value let website_url = $("#websiteurl").val(); // get the website url value }); });

  1. Or you can do something like this and get an associative array with just the values:或者你可以做这样的事情并得到一个只有值的关联数组:

     $('#theForm').submit(function() { var $inputs = $('#theForm:input'); var values = {}; $inputs.each(function() { values[this.name] = $(this).val(); }); });

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

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