473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Use php to "echo" javascript on a web page

Hello Group,

does this make sense?? I have some java code that responds to
keypress events (the arrow keys)

<script language="javascript">
<!--

function keypressed(e)
{
if (e.keyCode == 37) { document.location.href = 'images/?p=100'; }
else if (e.keyCode == 39) { document.location.href = 'viewpix.php?
p=1009&s=1'; }
}

The trick is the document.location.href can (and should) change as i
navigate thru image choices.
it is possible to use 37 to go back to an image document.location.href
= 'viewpix.php?p=100&s=1';
and 39 to go to next image: document.location.href = 'viewpix.php?
p=100&s=3';

this is a case where the image displayed is: document.location.href =
'viewpix.php?p=100&s=2';

I was thinking about making a php function that uses variables for the
href code , and then
echoing a string like this: (with appropriate dink marks, etc)
define these variables:
$back = 'images/?p="$p"';
$i = some number form $_REQUEST['id'];
$next = 'viewpix.php?p=$p&s="$i"';
echo '<script language="javascript">
<!--

function keypressed(e)
{
if (e.keyCode == 37) { document.location.href =
'$back'; }
}';
I would set the variable values, and then write the code in the page.

Any tips will help. the href stuff would change as the image changes.

Thanks,

eholz1

Feb 26 '07 #1
2 2067
eholz1 wrote:
I was thinking about making a php function that uses variables for the
href code , and then
echoing a string like this: (with appropriate dink marks, etc)
define these variables:
$back = 'images/?p="$p"';
You won't interpolate $p if its inside single quotes - assuming $p is a php
variable which holds some value:

$back="images/?=\"$p\"";

but really those quotes should be urlencoded (although since you'll be
reading the value back into PHP, I can't imagine why you need/want the
quotes at all).
$next = 'viewpix.php?p=$p&s="$i"';
Lose the "" around $i, use double quotes around the whole string.

You seem to have a basic grasp of programming - take the time to read
sections I, III & IV of the manual properly.

C.
Feb 26 '07 #2
On Feb 26, 2:27 pm, Colin McKinnon
<colin.thisisnotmysurn...@ntlworld.deletemeunlessU RaBot.comwrote:
eholz1 wrote:
I was thinking about making a php function that uses variables for the
href code , and then
echoing a string like this: (with appropriate dink marks, etc)
define these variables:
$back = 'images/?p="$p"';

You won't interpolate $p if its inside single quotes - assuming $p is a php
variable which holds some value:

$back="images/?=\"$p\"";

but really those quotes should be urlencoded (although since you'll be
reading the value back into PHP, I can't imagine why you need/want the
quotes at all).
$next = 'viewpix.php?p=$p&s="$i"';

Lose the "" around $i, use double quotes around the whole string.

You seem to have a basic grasp of programming - take the time to read
sections I, III & IV of the manual properly.

C.
C et All,

Thanks for reminding me about the double quotes, cleaner.
I will check the manual (I assume it is the on-line PHP manual)

Thanks,

eholz1

Feb 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Flanagan | last post by:
Of course "echo" is working, but I've got a case where php doesn't seem to be sending out the result of an "echo." I'm probably doing something wrong, but I can't see it. I've got the following...
5
by: Jonny T | last post by:
hi, i want to echo the string '<?php' in a php script like : echo "<?php"; but when i try nothing gets displayed ... if I use echo "<\?php";
2
by: brianj | last post by:
Running php4.3.6 What i'm trying to do is exactly like the weather channell site when you click in the zip code box the text dissapears and you are free to type your zip. I can make it work by...
6
by: Fabrice Régnier | last post by:
Hi ;) Everything is in the title. the prob is "boo" is displayed ! Can you believe it ? Thanx for anyone who can help me. fabrice.
1
by: Ennio-Sr | last post by:
Hi all! I'm writing a script that presents the user with a numbered lines menu, each line corresponding to a <case n> which executes a psql command. As the psql-commands are very similar to each...
2
by: funkyj | last post by:
I've been googling around trying to find the answer to this question but all I've managed to turn up is a 2 year old post of someone else asking the same question (no answer though). ...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.