473,401 Members | 2,139 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,401 software developers and data experts.

php within javascript

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



May 4 '06 #1
3 1424
> 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
May 4 '06 #2
"Ben Holness" <us****@bens-house.org.uk> skrev i meddelandet
news:pa****************************@bens-house.org.uk...
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
May 5 '06 #3
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.
js*******@attglobal.net
==================
May 5 '06 #4

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

Similar topics

6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
7
by: David Hayes | last post by:
I tried finding an answer on http://www.quirksmode.org/ without success. I am attempting a complicated Frames structure. I have made it work in IE, but not Netscape. I begin with three...
4
by: Martin Feuersteiner | last post by:
Dear Group I'm using VB to write an aspnet application. I would like to call a javascript function from within a VB Sub or VB Function, is it possible? My code is something like this: VB...
17
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script...
13
by: ukrbend | last post by:
I'm new to Javascript and to html and am trying to make the following code snippet work but it doesn't. It refuses to call the getPage() function and I always get a 404 error. I know the code is...
2
by: Jon | last post by:
All, I'm currently working with a PHP-based CMS application, and am begining to put the finishing touches on it via Javascript validation. Currently, I'm using fairly standard methods of...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
9
by: misdst23 | last post by:
Hi, I know I can call a static java method within javascript by using the <% ... %tags. But how can pass a javascript variable ? function thefunction() { var = javascriptvariable ;
3
by: u0107 | last post by:
Hello, I have a multi-frame page. The frames are named Frame_1, Frame_2 and Frame_3. Frame_1 has a drop down box. When a value is selected in this drop down box, Frame_2 is updated using an...
9
by: Morlaath | last post by:
Is there a way to embed php within javascript code? I know that php is server side and js is client side. For instance when working with jsp, you can imbed jsp scriptlets within the js code. e.g...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.