Richard Richard - 11 months ago 60
HTML Question

Post "url-from' in a form

I want to know from which url a form is send. I've tried this, but the result is 'orgUrl' instead of the url where the form is send from.
Anyone an idea what's wrong with this code?

<input type="hidden" name="url" value=orgUrl>

<script>
$(document).ready(function(){
var orgUrl = window.location.href;
});
</script>

Answer Source

You're trying to mix javascript with normal html which is not possible. So you need to set the value also by javascript after getting the current url like this

<input type="hidden" id="url" name="url" value>

<script>
    $(document).ready(function(){
        var orgUrl = window.location.href;
        $("#url").val(orgUrl );
    });
</script>