By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Use php to "echo" javascript on a web page

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.