Hyperlink - JS Function & PHP Variable

if its possible to call a JavaScript function and pass on a PHP variable in 1 hyperlink?
I need to pass on variable: $lang=english And call JavaScript Function: javascript:loadScript1()


Set A Session Variable From A Hyperlink?

I want to click on a hyperlink and set a session variable. I've found examples on how to pass variables between pages but not within the same page.

I would prefer not to pass the variables via the URL because I want to keep the URL clean. I also gather that it is better coding practice to use session variables.

I dont want to pass the variables using a form whereby the user populates a textbox. Instead, I want the variables embedded within the url.

Here's an example of what I'm trying to achieve:

<body id="twoColLayout" class="<?php echo $_SESSION['submenu']; ?>">
<form action="index.php" method="POST">
<a href="index.php?submenu="search_bookmark">Search bookmarks</a>

Objective - When I select the link, the page reload with the variable 'submenu' set to 'search_bookmark'.
This then sets the class within the <body> tag. This is used for a CSS style sheet.

View 5 Replies View Related

Set A Session Variable From A Hyperlink...?

I've created a session variable to allow users to switch between UK and US content on the same site (UK default).

$_SESSION['territory'] = 'UK';
if (isset($_SESSION['territory'])){


All good so far. I now need a couple of links to set this variable when users click either UK or US. All I can Google is setting variables via forms, with nothing about setting via a plain old href.

View 3 Replies View Related

Echo Hyperlink Containing A Variable?

In the code below, I would like to make the word that prints out as the variable "$submittor" a hyperlink to [URL].

I can't get it to work; I think I'm doing the formatting wrong.

How can I do it?

echo '<div class="sitename3name">Submitted by '.$submittor.' on '.$dt->format('F j, Y &
bsp &
bsp g:i a').'</div>';

View 1 Replies View Related

Posting Variable From Hyperlink

The $id variable is showing up fine in this bit of code.  When I click the link it is supposed to pull the data from the database related to the $id.

Code: [Select]<a href='javascript: window.document.Vids<?php echo $id; ?>.submit();'>Watch</a>
<form name="Vids<?php echo $id; ?>" action="<?php echo $PHP_SELF; ?>" method="post">
<input value="<?php echo $id; ?>" type="hidden" name="Vids" />


I'm just not sure why the $id variable isn't being posted by my form and read by the code. 

View 1 Replies View Related

Creating A Hyperlink From A Variable In The Filename?

On one of my websites, I have non-web (.gpx) files available for download. At the moment, I just have links to those files in the HTML, but that isn't ideal.

What I would like to have is a gateway page that gives instructions on how to download and use the files, and a brief disclaimer as well. But I don't want to have to code up a gateway page for each and every download. What I would love to be able to do is something like:

<a href="/downloadgpx.php?file=route1">Download Route 1</a>

taking you to a gateway page "downloadgpx.php", which has the generic blurb about downloading the files, and then uses the query in the URL to generate a link to <a href="/downloads/route1.gpx">.

View 8 Replies View Related

Setting Session Variable In A Hyperlink?

My new site has 2 columns. The larger left side contains the blog. This transfers page's using $_GET and URL's.

My right column will contain profiles, registering, login-ins etc. I want this to use sessions to work out what page to display. This way things can come and go on the right column without disrupting the blog side of things.

The problem I am having is actually setting the session variable which this will run off. For example if I want to view someone's profile, it would typically be done in a link i.e. blog?viewprofile=John. This would disrupt the blog as you would go back to the index page.

I have thought about using hidden form fields but this seem's like a lot of hard work for what i would like to achieve. Before I go off making my site a complex form is there any other way to set sessions without using the URL to trigger events?

View 1 Replies View Related

Hyperlink Adding An Extra Gap To Variable

I have a php generated page with a hyperlink which opens in a new window

echo "<tr><td><a onclick="window.open('http://www.***.com/page/options.php?user_id=$user_id session_id=$session_id','options','width=590,height=200,toolbar=no,scrollbars=yes,resizable=yes,statusbar=no,directories=no,menubar=no,location=no');return false;" href="">$user_id</a></td></tr>";

The problem occurrs at options.php?user_id=$user_id The resulting hyperlink on the generated page adds a space to the user id after the "=" So when options.php loads.. it results in the user's id having an extra %20 at the beginning of their name Example.. The first page links to this. [URL]... When options.php loads it prints "This is %20Eejut's Options Page" I've tried using trim($user_id) before printing the hyperlink to the main page (that calls options.php) and the space still occurrs in the hyperlink Anyone know what's going wrong?

View 9 Replies View Related

Set Session Variable After User Clicks Hyperlink?

MySQL server version 4.1.14
PHP version 4.3.11

I've been helped so much already by reading other's posts and answers to a few of my own questions on this forum. A client logs in. If successful, the client is sent to a page that lists their projects. The projects are listed with a hyperlink. The hyperlink contains two variables: client name and project_id

PHP Code:

<a href="[[url]www.website.com][/url]' . $row['project_id'] .'&client=' .$u .'"> ' .$row['project_name'] . ' </a>

project_id is obtained from the database query and $u is the username obtained from the session variable set at login. After clicking the hyperlink, the client is taken to a page that lists the documents associated with that project. It all works, which was a big celebration! However... I noticed that if I change the project_id number in the hyperlink, the page updates with the documents pertaining to that project, even if they don't belong to that client! Yikes! But, if I change the client name, nothing happens. Is that because the client name was pulled from the session variable?

What I need is a way to limit each client to only viewing those projects and documents that belong to them. I thought maybe I could set a session variable when the user clicks on the hyperlink (thereby choosing a project), but am not sure how to pull that off!

PHP Code:

session_start(); //start the session
if (!isset($_SESSION['username'] ))


View 6 Replies View Related

Correctly Making A <a Href> Hyperlink With A Variable?

I'm trying to make a small script for my site where the user would go to the page, lets say, http:[url]..... From there, a script would read the 'p' variable, and result with a hyperlink going to http:[url]..... So far, this is what I have coded:

$test = $HTTP_GET_VARS['p'];
<a href="diffdir/".$test.">Test</a>

Now, I would think that inserthing that $test into the <a href> would do the trick, but sadly the hyperlink only leads to http:[url].....

View 3 Replies View Related

Setting A Session Variable Via A Hyperlink, Then Redirect

I usually have my nose in photoshop or flash, so PHP is still very new to me.  The project I've been given is to have a spanish version of our cardholder site.  The way I've achieved it so far is..

Create a php file that has all of the english/spanish translations in arrays.  An example would be Code:

View 5 Replies View Related

Getting This Hyperlink To Function In PHP, Has Java

I am trying to get a hyperlink with embedded php to work also with a java function. The goal is to get all the data associated with the 'diw_id' record. The link, in it's current, non-working state: Code:

View 3 Replies View Related

Calling Php Function On Click Of A Hyperlink

How to call a php function on click of a hyperlink?

View 2 Replies View Related

Catch From Html Code Hyperlink Tag's Href Atribute Content If Hyperlink Contains Search Condition?

my problem is in regular expression. I need to catch from html code hyperlink tag's href atribute content if this hyperlink contains search condition.here is snippet:

$a = "nail"; //search ctriteria between <a></a>
$s =<<<EOF
<a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&module=1&category=11" style=""> kaut kas cits </a>
<img> </img>

View 2 Replies View Related

Html - Calling Function On Hyperlink Onclick Event?

I am using AJAX for pagination in my application. So I am generating hyperlinks with for loop. as follow:

for($t=1; $t<=$hf; $t++)
if($t == $_GET['pageno'])
echo $t." ";


Above echo statement does not give call to function. But instead of this when i just write html hyperlink it works fine and I get to see page2.html, my HTML code is:

<a id="page2" href="javascript:void(0)" onclick="open_page('ajaxinfo.php','content'); javascript:change('page2');">page2</a>

View 2 Replies View Related

Disable The Hyperlink Or Change The Hyperlink To Link?

I am fetching some text from some site, at the same time it is fetching hyperlink in the text, I want to disable the hyperlink or change the hyperlink to my own link. I heard like I can use CSS or something to do this

View 3 Replies View Related

Function For Checking The Existence Of Variable - If The Variable Doesn't Exist Then Write A Default Value For The Variable?

i'm in need of a php function whose first argument will check that the variable exist or not outside of the function, if variable exist then echo it's value and if the variable doesn't exist then echo a default value for the variable given in second argument of the function. and in last remove(delete) both the variable passed to the function just after echoing their values.

simply :

function if_exists ($argument, $default)
// if $argument exist then echo it's value and then remove $argument variable.
// if the $argument doesn't exist then echo it's $default value and then remove $default variable.

i will use it like this :

if_exists ($any_variable, 'this variable is not defined');

this code is not doing the perfect job for me :

function if_exist(&$argument, $default = '')
if (isset ($argument))


View 1 Replies View Related

Cakephp Inheritng Controller Variable In Function From Another Function Variable?

is there a way we can get variable from another function for the current function in controller and user set function to use in corresponding view file?Sorry guys I meant passing view file variable to another view file...Below is the code...

function get_random_color()


View 2 Replies View Related

Pass A JavaScript Variable To A Function Or Simply Assign A Js Variable To A Variable?

Is there any way to pass a javascript variable to a php function or simply assign a js variable to a php variable....?

test("asdas"); I need to update "asdas" to a dynamic value, i.e of the form,

View 3 Replies View Related

Acessing Outher Function Variable From Variable Function?

It is a bit hard to explain so I'll just show an example:

function foo()
$a = "changed by variable function";


View 2 Replies View Related

HTML - Isset Function - Check The Id Variable Has Been Set And If Not Then Default The Variable To Category 0

I'm fairly new to PHP and am creating a website for my company. I am using some existing code that I have obtained but can't seem to make it work properly. I have a variable, $id, which identifies the product category type to display on the page. I first need to check that the id variable has been set and if not, default the variable to category 0. The code I have is as follows:

setdefault($id, 0);
function setdefault(&$var, $default="")
if (!isset($var))
$var = $default;

So with the address [URL], I would expect it to default to $id=0; with the address [URL], I would expect it to set $id to 3 and display the relevant products. However, despite setting $id, it still defaults to 0.

View 5 Replies View Related

Value Of A Local Variable Of A Function Has To Be Retained Over Multiple Calls To The Function?

The value of a local variable of a function has to be retained over multiple calls to the function. How should that variable be declared in PHP?

View 1 Replies View Related

Access A Variable Inside The Parent Function From A Child Function?

I have some piece of code that is nested like this

$variable = 'This is a global argument';
function parentFunction($variable) {

What I want to know is - Is there a way to access a variable from the parent function without passing arguments to the child function? (Something like how classes have parent::?). I don't want to use $GLOBALS because it might cause some variable collision, and I didn't want to pass arguments because incase I decide to change the arguments in the parent function I'd have to do it in the child function aswell.

View 5 Replies View Related

Passing Variable To A Function - Value Is Not Accessed Inside The Function

i am extracting a data from the url. www.somesite.com/somefile.php?usrname=hello
i had extracted hello from this url by using $var=$_GET['usrname']; i passed this $var as a parameter in a function $var.But that value alone is not accessed inside the function why?

View 2 Replies View Related

Avoid The Function Call When Passing A Function Variable?

I have a function variable like this...

$aName = "My Name";

The function need to pass in like this:

$sayHelloFunction = function sayHello($aName){

View 6 Replies View Related

Call A Function Using A Function Name Generated From A String Variable?

In the process of automating some code, I am looking to call upon a function based on what a string is. For example, I have a variable $somevar which is set to the string "This". Now I want to run a function doThis(); So, I was hoping I could write do.$somevar($var,$var2) . I want it to run doThis($var1,$var2).

View 6 Replies View Related

Pass Function As Variable And Then Call It Using That Variable?

How can I pass a function as a variable and then call it using that variable? e.g.

function test($function)

View 3 Replies View Related

Passing Variable Into Function - Referencing The Variable?

I have a class which pulls in Twitter feeds and amalgamates them, they are put into an array ,sorted and combined. I then need to convert the 'published' time from unix to human . Within my class construct I have:

function __construct($inputs) {
$this->inputs = $inputs;


Part of this I believe is due to my lack of understanding of PHP terminology, which is making it hard to find anything in the manual . Am I trying to reference the 'published' array? What I need is the correct version of :


View 2 Replies View Related

Displaying The Value Of An Incremental Variable {Variable} Outside The Function?

I have the following function that sets up a slideshow in Wordpress. It sets several variables that are dependent on another incremental variable $i. I am trying to find a way to call these variables in my template file so it displays their values. I am envisioning using something like <?php echo $tzDesc; ?>. he defined variable look like this: $tzDesc = $custom["slide{$i}-desc"]; where it is referring to the value saved in a custom field. Each slide has a custom field of a similar name only differing by the incremental number, the value of $i. I can display them here in this line $page = "<h2>{$tzTitle}</h2><img src='{$tzImage}' />"; and it shows up on my page correctly, however I want more flexibility to call the values in different parts of my template file rather than having to define the entire template file in that one line of the function.Here is the function:

add_action( 'the_post', 'paginate_slide' );
function paginate_slide( $post ) {
global $pages, $multipage, $numpages;


View 2 Replies View Related

Redefining A Variable By Referencing The Variable In A Function?

Gee Wiz finding the vocab to express the question can be pretty tricky, but hopefully you can tell me what's wrong with referencing a variable in a function in order to change it.Example:

$a = 5;
$something = 5;


View 1 Replies View Related

Function To Check Variable Exist Or Not Outside Of Function?

i am in need of a php function to check that a variable exist or not outside of function, if it does not exists then assign a default value to it. function will be something like : function if_exist($argument, $default = '') , where $argument will be any variable outside the function it can be a variable's variable, and $default will be the default value of the variable if the variable doesn't exists,

View 5 Replies View Related

Pass Value Of A Variable In One Function To Another Function In Same Class?

I have a class Block_Model (actually a MODEL in KOhana framework) with 2 functions input() and output().The function input is called from a function wriiten inside a controller called Home_Controller and it passes an argument to the function input. Now I want that argument passed to input() function to be accessible in the function output(). Both the functions input() and output() are inside Model class Block_Model.

View 2 Replies View Related

Static Variable In Function Set By Calling Another Function?

I'm working in PHP. I have a function (F1) that gets called a variable amount of times. Within that function, I need to load a constant data set from another function (F2). It's always the same data set loaded, however loading the set involves some database lookups and processing. Rather than call F2 repeatedly and increase overhead/redundancy/processing requirements, I would like to put the result into a static variable in F1. However, for whatever reason, it will not allow me to set the variable as static using the function call.

A code example:

function calledRepeatedly() {
static $dataset = loadDataset();
// some minor processing here using the dataset
// and probably a loop
return "stuff";
function loadDataset() {


The above does NOT work. It results in an error -- unexpected '(', expecting ',' or ';' I do realize that it would work, and it would be passed by reference thus eliminating overhead, however that involves the extra work of making sure that calls to calledRepeatedly actually have the dataset in the arguments list.Is there any way to do this?

View 3 Replies View Related

Variable In A Function In Another Function Called From A Preg_replace_callback?

I want to get absolute URLs for my screen-scraper app that will get HTML code and render it in the browser with a few changes to spelling etc. To make sure it grabs CSS and images properly I have played about with different ways of getting absolute URLs

I ended up with the following code:
Code: [Select]<?php

View 9 Replies View Related

Variable Scope - Function In Function

Here's something that I can't manage to find explicitly documented. In the
following snippet:

function outer() {
global $a;
function inner() {
global $a;
echo $a.&#391;<br>'
$a = 's'
echo $a.&#392;<br>'


If either of the globals statements is removed, the variable is not
accessable within inner.

View 6 Replies View Related

Variable Inside Function Use It Outside Function?

Im including almost every page in page_protect(); . I have made an variable for the userid, $userid, with the user´s id. So it will be much easier for me to get the id than calling SESSION_id each time on every page.

How can i use a variable inside that function outside the function?

View 1 Replies View Related

Get Variable From Function Inside Another Function?


How to get values of this function inside an another function? Like:


We know that $variable_id (id is numeric) already exists in first() $list is an Array(), which can have more than 100 values.
$ordinary_variable is a string.

View 2 Replies View Related

Access Variable In Function From Another Function?

I have this function

PHP Code:

function theme_status_time_link($status, $is_link = true) {
$time = strtotime($status->created_at);
if ($time > 0) {


I need to pass the variable $out from the first function to the second function, precisely to the $html variable in the second function. So I could echo everything. However, everything I try either gives me errors and outputs nothing. Without using globals because it appears multiple times in my script.

View 7 Replies View Related

Passing A Function Variable To Another Function?

is there a way to do that and pass the hey() variable into the say()?

PHP Code:

function hey () {$hey = '1';}function say() {echo hey() . ' test';} 

I dont understand what return does, i tried return $hey.

View 4 Replies View Related

Call A $variable Inside One Function That Was Defined Previously Inside Another Function?

I'm just starting with Object Oriented PHP and I have the following issue: I have a class that contains a function that contains a certain script. I need to call a variable located in that script within another function further down the same class. For example:

class helloWorld {
function sayHello() {
echo "Hello";


in the above example I want to call $var which is a variable that was defined inside a previous function. This doesn't work though, so how can I do this?

View 3 Replies View Related

Copyrights 2005-15 www.BigResource.com, All rights reserved