Hyperlink - JS Function & PHP Variable

Feb 7, 2002

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()

View 7 Replies


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

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

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

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

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

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

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

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

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

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

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

Calling Php Function On Click Of A Hyperlink

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

View 2 Replies

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

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

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

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

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

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

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

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

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

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

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

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

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

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