Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Set JS variables with PHP
Old 11-27-2008, 10:52 PM Set JS variables with PHP
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Hey all,

I have some javascript on the main page of my website that changes the news image and header every 7 seconds in a <div>. I have it set up working fine but I dont want to be able to just update my database as opposed to having to update the code everytime the news changes. Whats the easiest way to set Javascript variables with PHP?

I know AJAX deals with PHP and JS interaction but I have never played with that before. Any pointers? Preferably something simple that wont slow down the loading of the page too much (I guess thats always the idea though :P)

Thanks

EDIT:
Actually I just answered my own question. Because I am just setting variables and not running anything I just add the PHP code into the JS where I want it.

PHP Code:
<script type="text/javascript">
var bigTitle = new Array();
bigTitle[1]="<?php echo $firsttitle?>";
bigTitle[2]="<?php echo $secondtitle?>";
</script>
I just put this in the body of the page and then call the JS function in the head. By doing this I can query the database with PHP right before the code I just pasted in order to set the varialbes.

Hopefully this helps someone else too.
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE

Last edited by Truly; 11-27-2008 at 11:18 PM..
Truly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Set JS variables with PHP
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.08351 seconds with 12 queries