0

I have an html form and I need to populate one of the input fields with the url of the page the form is on. To get the url I have:

<?php $pageURL="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?>

To populate the input field I have:

<script type="text/javascript">
// <![CDATA[   
$(document).ready(function(){
    var getLabel = $(".monkForm label:contains('Page URL')");
    var getFor = getLabel.attr('for');
    var splitFor = getFor.split('_');
    var inputID = $("#" + getFor );
    var wrapID = $("#w" + splitFor[1] );
    wrapID.hide();
    inputID.val('<?=$pageURL;?>');
});
// ]]> 
</script> 

The input field label on the form is "Page URL". The problem is that the page URL is not being added to the input field.

1
  • 2
    don't use the php function, simply use window.location.href to grab the url. Commented Jun 25, 2012 at 20:20

2 Answers 2

1

You can't use PHP as it is server side. Get the URL using Javascript instead:

inputID.val(window.location.href);
Sign up to request clarification or add additional context in comments.

Comments

1

you rather than use:

inputID.val(window.location.href);

don't use php statment.

Comments

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.