Hi,
I have a form that submits automatically after it collects data into a hidden field. This form has an action URL. I want to know how I can append the data from the hidden input field to the action URL.
Here is what I have:
<form action="http://www.site.com/" method="post" name="hidden_form">
<input name="website" type="hidden" value="%%9011{html}%%" />
<!-- The value is generated dynamically by the system which should be a site URL like http:///www.google.com/ etc... -->
</form>
<script>
document.hidden_form.submit(); // Submits the form Automatically.
</script>
My question is how do I append the value of website to the action URL so it should look like this:
Just so you know the URL site.com/ is looking for a website URL after the trailing slash so it can perform some sort of Analytics on that domain.
Help is appreciated. It has to be jQuery/Javascript as this form is a third party form and they only allow JS to be embedded.
Or possibly just on document.ready update it since you don’t need to wait for the form submit to append the forms action. I’d actually go with this option.
Edit - I updated the codepen to be on document.ready instead of on form submit.
Here’s one approach at cleaning it up, by using some named variables to help aid understanding.
$(document).ready(function() {
// Add a hidden value to the form action
var domain = $("#whatever").attr("action"),
site = $("input[name=website]").attr("value");
$("#whatever").attr("action", domain + site);
});
The form submits to another page with a hidden form.
This hidden form gets the URL and submits automatically appending the website URL value to the action URL
In my static example, the first page isn’t really passing a value to /onwards.html - but just wanted to share the whole flow.
On onwards.html, you shouldn’t really have to click the submit button as it should submit automatically. I just have it there for troubleshooting. If you want to ignore the index.html page you can as that just feeds onwards.html.