PHP & JS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

PHP & JS

Post by JellyFish »

I was wondering if it's ok to use javascript and php in the same script meaning can I have JavaScript in a php file type? The reason I ask this is because I'm trying to do just this. The JS code only makes it say theres an error on the page down in the status bar. All help is appreciated.

Thanks.
User avatar
quocbao
Forum Commoner
Posts: 59
Joined: Sat Feb 04, 2006 2:03 am
Location: HCM,Vietnam
Contact:

Post by quocbao »

I was wondering if it's ok to use javascript and php in the same script
it's ok to use javascript and php in the same script

Code: Select all

<script language=javascript>
alert('Time : <?=date('H:i:s')?>');
</script>
The JS code only makes it say theres an error on the page down in the status bar.
Check your javascript.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Thanks for your answer. That's all I really needed to know but what is the JS code you gave suppose to do? I think you mean it just displays the error in the status bar. You don't have to answer but I was just wondering.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

That is just an example of alerting time try this:

Code: Select all

<?php
echo '<script language="javascript">';
echo 'alert(\'hello world\');';
echo '</script>';
?>
if it does not work view the source of the page and show us the exact code
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Thanks jshpro2.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

How would you JS alert something with a string in it like alert('$blah')

How would I do something like that.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

play with it a while nickman.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

lol im an idiot.

thanks.
Post Reply