get title of the current page using javascript

hi guys,anyone can help me how to get title of the current page using javascript and the value of title will be using  in the php script because i want to save the title in database
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.

mozerukCommented:
document.title gives you the text content of the <title> element. You
can also set document.title in most current browsers.

The element itself can be accessed like any other element using e.g.
var titleElement;
if (document.getElementsByTagName) {
titleElement = document.getElementsByTagName('title')[0];
if (titleElement) {
// use titleElement here e.g.
alert(titleElement.nodeName);
}
}
0
Om PrakashCommented:
You can use HIDDEN variable to store the value on click of submit button which can be later used to store the information in database.
//Call this function on click of button
function SaveTitle()
{
document.form[0].yourhiddenfield.value = document.title;
}

You can use yourhiddenfield in the PHP code to save in DB.
0
agilentwaxAuthor Commented:
hai mozeruk and om prakash p, i have use this code <script language="JavaScript">
alert(document.title);</script>  to get the title of the page,it i dont want the popup to display on the page..how to only get the title without the popup..

mozeruk,i have try ur code but i need to set the title rite..and om prakash can u show me how to use ur code u means i need to have input button rite..
eg. <input type="submit" name="submit" value="bookmark" onclick="SaveTitle()"/>
and how to use hidden field to save in db
title.png
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!

Dhanasekaran SengodanCommented:
create a hiddencontrol


<input type="hidden" name="hidtitle" />

function SaveTitle()
{
document.form[0].hidtitle.value = document.title;
}





0
Om PrakashCommented:

<script>
function SaveTitle()
{
document.form[0].hidtitle.value = document.title;
document.form[0].submit();
}
</script>

<form method="post">
<input type="hidden" name="hidtitle" />
<input type="submit" name="submit" value="bookmark" onclick="SaveTitle()"/>
</form>

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
agilentwaxAuthor Commented:
thnks om prakash, i have try ur code..but i dont get any value from it....can i get the value from javascript without using hidden control or form i means by using this

$title="<script language="JavaScript">alert(document.title);</script>";

i want use the value in $title in href code like this <a href="insert.php?gid=<? echo $gid ?>&sid=<? echo $sid?>&url=<? echo $url?>&tit=<?php $title ?>&id=<? echo $id ?>"
0
agilentwaxAuthor Commented:
so om prakash just ignore my last comment..so now i use ur code to get the title of the page..but it not return any value on the url
0
agilentwaxAuthor Commented:
it give me some idea  to solve my problem
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
JavaScript

From novice to tech pro — start learning today.