473,394 Members | 1,642 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,394 software developers and data experts.

PHP in JS?

Hi!
I have some menu buttons on my page 'somepage.php' which I've made in JS:
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2.     rollImage1 = new Image; rollImage1.src = "menu_b1_over.gif";
  3.     defaultImage1 = new Image; defaultImage1.src = "menu_b1.gif";
  4.     rollImage2 = new Image; rollImage2.src = "menu_b2_over.gif";
  5.     defaultImage2 = new Image; defaultImage2.src = "menu_b2.gif";
  6.     rollImage3 = new Image; rollImage3.src = "menu_b3_over.gif";
  7.     defaultImage3 = new Image; defaultImage3.src = "menu_b3.gif";
  8.     rollImage4 = new Image; rollImage4.src = "menu_b4_over.gif";
  9.     defaultImage4 = new Image; defaultImage4.src = "menu_b4.gif";
  10. </script>
  11.  
here goes some other elements of the page....
Expand|Select|Wrap|Line Numbers
  1. <a href="???????" target="data" onMouseOver="document.myImage1.src = rollImage1.src;"
  2.     onMouseOut="document.myImage1.src = defaultImage1.src;">
  3.     <img src="menu_b1.gif" name="myImage1" border=0></a>
  4. <a href="????????" target="data" onMouseOver="document.myImage2.src = rollImage2.src;"
  5.     onMouseOut="document.myImage2.src = defaultImage2.src;">
  6.     <img src="menu_b2.gif" name="myImage2" border=0></a>
  7. <a href="????????" target="data" onMouseOver="document.myImage3.src = rollImage3.src;"
  8.     onMouseOut="document.myImage3.src = defaultImage3.src;">
  9.     <img src="menu_b3.gif" name="myImage3" border=0></a>
  10. <a href="????????" target="data" onMouseOver="document.myImage4.src = rollImage4.src;"
  11.     onMouseOut="document.myImage4.src = defaultImage4.src;">
  12.     <img src="menu_b4.gif" name="myImage4" border=0></a>
  13.  
Is it possible to use PHP inside JS? JS can solve the menu (rolling over the images--> buttons), but I want to process the user's choice from the menu to PHP, so the script can load the appropriate content to the 'data' frame...
Can I use php script at the ??????? inside JS to find out the user's choice from a select menu for example? Hope I was clear....
Aug 25 '06 #1
10 2604
vssp
268 100+
yes ites possible to inside the java script using php.
But not reterive any variable
Aug 25 '06 #2
iam_clint
1,208 Expert 1GB
actually you can retrieve a variable in a sense



Expand|Select|Wrap|Line Numbers
  1. function test() {
  2.   var blah = "<?=blah?>";
  3. }
  4.  
Aug 25 '06 #3
vssp
268 100+
Hi friend

Yes here is teh example

<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2">
alert('Your score is <? echo "$variable" ?> . Thank you for playing.');
</SCRIPT>
</HEAD>
<BODY>
Main text here…
</BODY>
</HTML>
Aug 26 '06 #4
vssp
268 100+
This is anoter example
<?
echo "<script language=\"JavaScript\">\n";
echo "alert("javascript from php");\n";
echo "</script>";
?>
Aug 26 '06 #5
ronverdonk
4,258 Expert 4TB
Turn your question around: "JS in PHP?"

In my experience, the easiest way to use JavaScript is from within the PHP code. So i would recommend the solution given by VssP in the previous reply.

Ronald :cool:
Aug 26 '06 #6
Okay.. here's a question for you:

I have been trying to get my Javascript to work on my php page and it doesn't seem to want to. I was beginning to think that maybe you couldn't do that. But obviously from what you guys are saying you should be able to.

So here's my php in which I tried to insert some JS in the echo statement:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if ($page == 'index') 
  3. {
  4. echo "<img border=0 src='images/homenew.gif'>";
  5. }
  6. else
  7. {
  8. echo "<a href='http://www.healthy-connections.org/index.php' title='Healthy Connections Home'><img border=0 onmouseover='this.src=images/homebehind2.gif;' onmouseout='this.src=images/homebehind.gif;' src='images/homebehind.gif' style='margin-left: 0px;'></a>";
  9. }
  10. ?>
  11.  
Am I doing something wrong?

Thanks,
Elizabeth
Aug 26 '06 #7
iam_clint
1,208 Expert 1GB
i don't see any javascript in that besides the on mouse over out and click event... whats the page doing
Aug 26 '06 #8
Nothing and that's the problem. That is all the JS I'm trying to use. A super-simple onmouseover and onmouseout to swap out images on the navigational buttons. Shouldn't be a problem, right? The page is completely ignoring it like it is not even in there.

I find it obvious that it has something to do with the fact that it's in a .php file because I had this same html (w/ JS) in an .html file and it worked like I thought it should but when I copied and pasted it into my .php it did not.

And THAT, my friends, is why I am baffled. : )
Aug 28 '06 #9
bevort
53
Look at the result of your php file by viewing the source and copying it into a syntax sensetive editor. You will see probably some errors.

Also when you have the result in your browser you can see that there is an error and where to find it. IE is very bad in pointing out where the error is.

Om a mouseover() image swapping yoou have to load both images first before calling them in the swap script. Try a javascript site for some details on this.

It really is possible and I do note see any error in your lines of code
Aug 30 '06 #10
Is it possible to use php code inside the JS tags?
Expand|Select|Wrap|Line Numbers
  1. <script src="<? =$some_php_variable?>.js" language="JavaScript1.2"></script>
  2.  
?????????
Sep 12 '06 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.