0

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

1 Answer 1

1

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'].

Sign up to request clarification or add additional context in comments.

1 Comment

This worked - I just used the variable referrerPage.val(window.location); Works a treat! Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.