[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

get value from javascript pass to php code

Posted on 2010-04-08
6
Medium Priority
?
317 Views
Last Modified: 2013-12-12
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;?>"/>
0
Comment
Question by:agilentwax
  • 4
6 Comments
 
LVL 6

Expert Comment

by:blueghozt
ID: 30101147
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
 
LVL 6

Accepted Solution

by:
blueghozt earned 2000 total points
ID: 30101216
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
 
LVL 6

Expert Comment

by:blueghozt
ID: 30101315
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Expert Comment

by:anas5_2007
ID: 30128499
just do this:
<script>
$("#title").val(document.title);
</script>

in php page:
$title = $_POST['title'];
0
 
LVL 6

Expert Comment

by:blueghozt
ID: 30128995
@anas5_2007 wouldn't your solution require something like jQuery to work?
0
 

Author Comment

by:agilentwax
ID: 30165965
thanks blueqhozt.its working..that's code what i'm looking for..thnks bro for help me
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question