[英]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:这是我所做的:
Email input field id: email
Email 输入字段ID:
email
Website URL input field ID: websiteurl
网站URL 输入字段ID:
websiteurl
Submit button ID: analysee
提交按钮 ID:
analysee
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.感谢您的时间。
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 }); });
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.