Append value from hidden field to form action URL

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.

Thanks!

I’m sure this can be cleaned up.
http://codepen.io/ryanreese09/pen/OVywJZ?editors=101

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);
});

1 Like

For some reason it does not work. I uploaded the test files here: http://conradabraham.com/clients/forwarding/

  1. Go to http://conradabraham.com/clients/forwarding/ and fill in a URL
  2. Click Submit
  3. The form submits to another page with a hidden form.
  4. 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.

Hope this brings clarity.

Thanks!

Look at the JavaScript console. I see an error that $ is not defined. Do you see that same error?

That implies that jQuery isn’t available. Looking at the page source, it is confirmed that you need to add that there.

What do you know. That was the problem. Thanks. I was able to get this working. Thanks to all in this thread!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.