get value from javascript pass to php code

hi guys i want to get title of the current page using javasript,and save into variable..and i will use the value in variable to php using hidden field..so its correct to do like this
this javascript code to get page title and save in $title variable
$title = "<script language='javascript'>document.title;</script>";

<input type="hidden" name="title" id="title" value="<?php echo $title;?>"/>
agilentwaxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

blueghoztCommented:
Hi, you do not need to use PHP for this (unless you need to elsewhere!)

simply paste this into your page where your input should be
<input type="text" id="title" name="title" />
<script>
var pagetitle = document.title;
obj = document.getElementById("title");
obj.value = pagetitle;
</script>

Open in new window

0
blueghoztCommented:
sorry, saw you wanted it hidden:
<input type="hidden" id="title" name="title" />
<script>
var pagetitle = document.title;
obj = document.getElementById("title");
obj.value = pagetitle;
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
blueghoztCommented:
also - if the field is included in a form that is submitted to a PHP script then the value will be available to your PHP script as $_POST['title']
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

anas5_2007Commented:
just do this:
<script>
$("#title").val(document.title);
</script>

in php page:
$title = $_POST['title'];
0
blueghoztCommented:
@anas5_2007 wouldn't your solution require something like jQuery to work?
0
agilentwaxAuthor Commented:
thanks blueqhozt.its working..that's code what i'm looking for..thnks bro for help me
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.