469,572 Members | 1,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

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 1944
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Flanagan | last post: by
5 posts views Thread by Jonny T | last post: by
2 posts views Thread by brianj | last post: by
6 posts views Thread by Fabrice Régnier | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.