I created a form using Elementor Pro Form widget. Now I want to write some code and I need to get the value of the input fields from the Elementor Pro Form. How can I do that?
Here is what I did:
Email input field id: email
Website URL input field ID: websiteurl
Submit button 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?
You can use the val() property to retrieve the input's value, by doing something like this:
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();
});
});