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()
View 7 Replies (Posted: February 7th, 2002, 06:17 AM)
Sponsored Links:
Related Forum Messages:
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: <?php session_start(); ?> <body id="twoColLayout" class="<?php echo $_SESSION['submenu']; ?>"> <form action="index.php" method="POST"> <a href="index.php?submenu="search_bookmark">Search bookmarks</a> </form> 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.
Posted: 12-15-2009, 06:54 AM
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). <?php session_start(); $_SESSION['territory'] = 'UK'; if (isset($_SESSION['territory'])){ [code]... 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.
Posted: May 24 10 at 15:41
View 3 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" /> </form> [Code]..... I'm just not sure why the $id variable isn't being posted by my form and read by the code.
Posted: April 10, 2011, 09:57:56 PM
View 1 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>';
Posted: Jun 16 10 at 18:08
View 1 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?
Posted: June 05, 2007, 06:21:04 AM
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">.
Posted: Oct 12, 2010, 15:33
View 8 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?
Posted: November 26, 2009, 06:39:01 PM
View 9 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:
Posted: October 15, 2007, 10:02:30 AM
View 5 Replies!
View Related
Set Session Variable After User Clicks Hyperlink?
MySQL server version 4.1.14 PHP version 4.3.11 phpMyAdmin 2.11.9.6 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: <?php session_start(); //start the session if (!isset($_SESSION['username'] )) [code]....
Posted: Mar 6, 2010, 15:32
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: <?php $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].....
Posted: Dec 27 09 at 16:49
View 3 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." "; [Code]..... 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>
Posted: Jun 23 10 at 10:35
View 2 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 : $any_variable 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)) { [code]....
Posted: Jul 12 at 8:51
View 1 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.
Posted: Mar 2 09 at 18:35
View 5 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) { [code].... 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.
Posted: December 28, 2010, 06:54:17 AM
View 5 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; $this->mergeposts(); [code].... 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 : $this->sorted['published']
Posted: Mar 22 at 10:23
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; [code]...
Posted: Dec 8 10 at 17:09
View 2 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,
Posted: Jul 10 at 21:08
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.
Posted: Jun 9 at 7:16
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() { [Code]... 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?
Posted: Dec 7 10 at 17:12
View 3 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.Ƈ<br>' } $a = 's' inner(); echo $a.ƈ<br>' } outer(); ?> If either of the globals statements is removed, the variable is not accessable within inner.
Posted: May 21st, 2006 07:05 PM
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?
Posted: Sep 4 10 at 17:49
View 1 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) { [code].... 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.
Posted: July 12th, 2011, 06:28 PM
View 7 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"; [code].... 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?
Posted: Mar 20 10 at 15:51
View 3 Replies!
View Related
|