Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

php within javascript

 
   Database Forums (Home) -> PHP RSS
Next:  PHP instances writing to the same file?  
Author Message
Garry Jones

External


Since: Apr 10, 2006
Posts: 12



(Msg. 1) Posted: Thu May 04, 2006 11:57 pm
Post subject: php within javascript
Archived from groups: comp>lang>php (more info?)

For a photo display I am using a javascript I found on the net (freeware).
The Java script code has to be placed within head and /head tags

The Java code consists of the start

<script language="JavaScript1.2">

Then about 150 lines of script followed by values I have to write in

and then about another 150 lines of Java script before the
</script>

The values I have to write in are the names of the files in this format

Pic[0] = 'img/2005/horiz/image0.jpg'
Pic[1] = 'img/2005/horiz/image1.jpg'
Pic[2] = 'img/2005/horiz/image2.jpg'
Pic[3] = 'img/2005/horiz/image3.jpg'

I have placed these in a php file and I use Include from the middle of the
java script to call these in. It works fine for these four files

As I have 3600 lines to write I would like to use a php echo to write the
lines into the java script. Something along the lines of

<?
i=0;
While ($i<3601){
echo "Pic[";
echo $i;
echo"] = 'img/2005/horiz/image";
echo $i;
echo ".jpg'";
i++;
}
?>

But it does not work and I have played around with the syntax and tried
varying methods. Is this because Java script does not like too much php code
and its conflicting. Or should I be able to use php code freely from within
the Java script and I have simply created a php syntax error.

The page fails to load. Checking the source code in MSIE reveals that it
stops working in the middle of the Java when it comes to the php code.

Any help appreciated.

A footnote to this is that I wonder what php++ does to the number "0" if it
is written "0000", would the "++" method give an output of 0001 or 1?

Garry Jones
Sweden

 >> Stay informed about: php within javascript 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 2) Posted: Thu May 04, 2006 11:57 pm
Post subject: Re: php within javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Garry Jones wrote:
> For a photo display I am using a javascript I found on the net (freeware).
> The Java script code has to be placed within head and /head tags
>
> The Java code consists of the start
>
> <script language="JavaScript1.2">
>
> Then about 150 lines of script followed by values I have to write in
>
> and then about another 150 lines of Java script before the
> </script>
>
> The values I have to write in are the names of the files in this format
>
> Pic[0] = 'img/2005/horiz/image0.jpg'
> Pic[1] = 'img/2005/horiz/image1.jpg'
> Pic[2] = 'img/2005/horiz/image2.jpg'
> Pic[3] = 'img/2005/horiz/image3.jpg'
>
> I have placed these in a php file and I use Include from the middle of the
> java script to call these in. It works fine for these four files
>
> As I have 3600 lines to write I would like to use a php echo to write the
> lines into the java script. Something along the lines of
>
> <?
> i=0;
> While ($i<3601){
> echo "Pic[";
> echo $i;
> echo"] = 'img/2005/horiz/image";
> echo $i;
> echo ".jpg'";
> i++;
> }
> ?>
>
> But it does not work and I have played around with the syntax and tried
> varying methods. Is this because Java script does not like too much php code
> and its conflicting. Or should I be able to use php code freely from within
> the Java script and I have simply created a php syntax error.
>
> The page fails to load. Checking the source code in MSIE reveals that it
> stops working in the middle of the Java when it comes to the php code.
>
> Any help appreciated.
>
> A footnote to this is that I wonder what php++ does to the number "0" if it
> is written "0000", would the "++" method give an output of 0001 or 1?
>
> Garry Jones
> Sweden
>
>
>
>
>
>
>

Garry,

I don't understand. Are you trying to call PHP code from Javascript? If so, it
doesn't work well - PHP is server-side, and Javascript (Not Java script!) is
client-side.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex.RemoveThis@attglobal.net
==================

 >> Stay informed about: php within javascript 
Back to top
Login to vote
Ben Holness

External


Since: May 03, 2006
Posts: 4



(Msg. 3) Posted: Fri May 05, 2006 12:28 am
Post subject: Re: php within javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> Or should I be able to use php code freely from within
> the Java script and I have simply created a php syntax error.

As far as my understanding goes, with Apache 1.2 or 2, php can be used
freely in javascript code as long as the file is named .php (or another
exension that is configured for PHP). If the javascript is in a .js file
while is included in the header with a link, then I am not sure if it
works.

Also, in your code you have:

> echo"] = 'img/2005/horiz/image";
> echo $i;
> echo ".jpg'";
> i++;
> }
> ?>

It's probably an email typo, but that needs to be $i++ on the fourth line
down.

Cheers,

Ben
 >> Stay informed about: php within javascript 
Back to top
Login to vote
Garry Jones

External


Since: Apr 10, 2006
Posts: 12



(Msg. 4) Posted: Fri May 05, 2006 2:15 am
Post subject: Re: php within javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Ben Holness" skrev i meddelandet


> It's probably an email typo, but that needs to be $i++ on the fourth line
> down.

I will check it again, thanks for your help. I deleted all my previous
attempts, I think it was an email typo, anyway, I will try this again now I
know it "should" work.

Garry Jones
Sweden
 >> Stay informed about: php within javascript 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
JavaScript to PHP? - I was just wondering that if it is possible to do almost anything you can do in JavaScript in PHP.

Javascript - I have a calendar formed with javascript. This line <script>this.form.orderdatefrom_Year_ID.value</script> returns the year-textbox.But in Javascript. How can I pass the javascript variable to php so to further use it?

php in javascript - I have create a checkbox,call getS function in onclick event. I append value of variable output with value $text. It works well but when I changed value of $text to a paragraph of text, it will occur error on the page. Please advise. Thanks. <script....

PHP or Javascript for this? - I'm wanting to create an hyperlink that will execute a mysql_query and then refresh the current page if it's clicked on. I've similar things created via javascript but didn't know if such was possible with PHP.

php using javascript objects - I want to initialize a TEXTAREA with text depending on the values already selected in other areas - input type=TEXT or SELECT. How can I set a PHP variable with a value retrieving those HTML object values ?
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]