Connecting Tech Pros Worldwide Help | Site Map

Use php to "echo" javascript on a web page

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 26th, 2007, 08:55 PM
eholz1
Guest
 
Posts: n/a
Default 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


  #2  
Old February 26th, 2007, 09:35 PM
Colin McKinnon
Guest
 
Posts: n/a
Default Re: Use php to "echo" javascript on a web page

eholz1 wrote:
Quote:
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).
Quote:
$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.
  #3  
Old February 26th, 2007, 11:25 PM
eholz1
Guest
 
Posts: n/a
Default Re: Use php to "echo" javascript on a web page

On Feb 26, 2:27 pm, Colin McKinnon
<colin.thisisnotmysurn...@ntlworld.deletemeunlessU RaBot.comwrote:
Quote:
eholz1 wrote:
Quote:
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).
>
Quote:
$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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.