Reputation: 3228
I'm wanting to get the current page URL on submit from my form and populate the "value" attribute on an input type hidden with the URL on submission.
Currently I'm statically adding in a URL (http://www.google.com) to see if I'm populating the value attribute the right way but using .val()
on the selector however, this doesn't seem to populate the attribute?
See my submit function below - I have added a class to the input called referrer-page
.
HTML
<input type="hidden" class="referrer-page" name="00N20000002A4au" type="text" value="URL HERE!" />
jQuery
setupOnSubmit = function () {
var submitButton = $j('.submit_form'),
emailIcon = $j('.email-icon'),
referrerPage = $j('.referrer-page');
emailIcon.on('click', function(){
$j(this).submit();
referrerPage.val("http://www.google.com");
});
//Pass URL on submit
submitButton.on('click', function(){
referrerPage.val("http://www.google.com");
});
};
Upvotes: 0
Views: 359
Reputation: 915
From your code it is not clear what all those functions do. Try something like this:
$('form').submit(function(){
$(':hidden[name="00N20000002A4au"]').val(window.location);
return true;
});
Code above is not tested, just an idea.
Also see $_SERVER['HTTP_REFERER']
.
Upvotes: 1