Solved

Can you Embed Java in php?

Posted on 2003-11-05
20
471 Views
Last Modified: 2012-05-04
Can you Embed Java in php? I am tring to create a dropdown menu that rediercts utilizing php.. is this possible? Any help would be appreciated, here is the code I have so far:

<?php
echo'<style type="text/css">
<!--
.style11 {
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 10px;
      color: #4D6185;
      font-weight: bold;
}
body {
      margin-left: 0px;
      margin-top: 0px;
      margin-right: 0px;
      margin-bottom: 0px;
}
.style12 {
      font-size: 9px;
      font-weight: bold;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      color: #4D6185;
}
.style13 {      font-size: 8px;
      font-weight: bold;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      color: #4D6185;
}
-->
 </style>
 
<script language=JavaScript>
function Navigate() {
var number = Manu.selectedIndex;
location.href = Manu.options[number].value; }
</script>

 
 
 
 
  <table width="139" border="0">
    <tr>
      <td><span class="style12">Search Manufacturer</span></td>
    </tr>
    <tr>
      <td>
       <form >
        <select name="Manu" size=".8" class="style12" id="Manu">
        <option value="http://www.turnthetides.com/Golf2/catalog.php?Callaway">Callaway</option>
        <option>Titleist</option>
        <option>TaylorMade</option>
        <option>Ping</option>
        <option>Mizuno</option>
        <option>Cobra</option>
        <option>Wilson</option>
        <option>Odyssey</option>
        <option>Teardrop</option>
        <option>Bettinardi</option>
        <option>Never Compromise</option>
        <option>See More</option>
        <option>Burton</option>
        <option>Belding</option>
        <option>Datrek</option>
        <option>Bennington</option>
        <option>Great Divider</option>
        <option>Foot Joy</option>
        <option>Dexter</option>
        <option>Nike</option>
        <option>Etonic</option>
        <option>Adidas</option>
        <option>Reebok</option>
        <option>Lady Fairway</option>
        <option>Jamie Sadock</option>
        <option>EP Pro</option>
        <option>Sport Haley</option>
        <option>Tail</option>
        <option>Tehama</option>
        <option>Zero Restriction</option>
        <option>Astra</option>
        <option>Ashworth</option>
        <option>Cutter &amp; Buck</option>
        <option>Polo</option>
        <option>Greg Norman</option>
        <option>Sports Haley</option>
      </select></td></tr></</form>
       </td>
    </tr>
    <tr>
      <td height="14"> <strong class="style12"><span class="style12">Search</span> Categorie </strong> </td>
    </tr>
    <tr>
      <td height="14"><p class="style12">
        <form name=SearchCats method=POST action="">
        <select name="Cats" size=".8" class="style12">
          <option>Golf Clubs</option>
          <option>Putters</option>
          <option>Golf Bags</option>
          <option>Golf Shoes</option>
          <option>Ladies Apparel</option>
          <option>Mens Apparel</option>
        </select></td></tr></</form>
      </p>      </td>
    </tr>
  </table>';
?>
0
Comment
Question by:bliesveld
  • 7
  • 5
  • 4
  • +3
20 Comments
 
LVL 6

Expert Comment

by:mattjp88
Comment Utility
Can you please explain the question more?  The code you currently have is just html being echod by php, nothing special, but i don't understand what you mean in your question.

thanks,
Matt
0
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
I don't see any applet or object tags there, so I assume you mean JavaScript.

You can embed JavaScript in PHP, in the same way as you can html.


From what I can see that is the output of a PHP page.
You can use Java Classes in PHP using the Java Extension. Check out http://www.php.net/java
0
 
LVL 1

Author Comment

by:bliesveld
Comment Utility
ya I am just using the php as a module on a larger website... I want to have the dropdown menus redirect to a page catalog.php and pass the var from the dropdown menu.  

here is the JavaScript I use:

<script language=JavaScript>
function Navigate() {
var number = Manu.selectedIndex;
location.href = Manu.options[number].value; }
</script>


here is an example of where I am going with the dd menu:
  <form >
       <select name="Manu" size=".8" class="style12" id="Manu">
        <option value="http://www.turnthetides.com/Golf2/catalog.php?Callaway">Callaway</option>
        </select></td></tr>
  </</form>


when I include the php in the main page the redirect javascript dosent work?
That is what I need help on.
0
 
LVL 17

Expert Comment

by:Squeebee
Comment Utility
What I can tell you is that I use plenty of Javascript on my pages, which is simply echoed out by PHP. If your Javascript has trouble, just look at your output HTML and debug your Javascript, then make the changed in the PHP echo and try again.

That being said, redirecting with Javascript can confuse some spiders (and browsers) and may not be the best approach. Navigation with a form and PHP page combination is at least more universal.
0
 
LVL 3

Expert Comment

by:red010knight
Comment Utility
Java and Javascript are two totally seperate programming languages. And since you are using js, I can help with it;-)

Let's see... you need to remove the </ in front of your close form tag and then put this
<select name="Manu" size=".8" class="style12" id="Manu" onChange="if(this.options[this.selectedIndex].value!='$'){window.open(this.options[this.selectedIndex].value,'_self')}">

now if you supply any options with the $ they will be ignored and could be considered like option seperators and so forth... try it and you will see what I mean

You can see an example of its use here:
http://faculty.erau.edu/ericksol/projects/issa/home_page1.html

hope that helps and you don't need that function navigate either;-)

Red010Knight
0
 
LVL 1

Author Comment

by:bliesveld
Comment Utility
Squeebee How would I go about using PHP and a Form for navigation?  I open to new implementations, and if its better I might as well learn how to do it.
0
 
LVL 17

Expert Comment

by:Squeebee
Comment Utility
Take the value chosen and perform a header redirect to move the user along.

Simply take the posted value of the form, build a URL, and send a header:

header("Location: http://www.newdomain.com/newpage/newurl.htm");
exit();
0
 
LVL 3

Expert Comment

by:red010knight
Comment Utility
As for Squeebee's comment:
 - redirecting with Javascript can confuse some spiders -
The method he is using is not a redirect otherwise he would be doing something like
<body onload="javascript:window.open("blah","_self");>"

So he won't confuse many spiders in fact it will almost aide in his site being searched because the select statement could work as a 'site map' although a small one, but the idea behind it is the same.

Red010Knight
0
 
LVL 17

Expert Comment

by:Squeebee
Comment Utility
I guess as long as the form options get spidered as URLs it will work out ok, but I suppose we agree that it still hinders javascript disabled browsers?
0
 
LVL 3

Expert Comment

by:red010knight
Comment Utility
The fact of using a form and php is more universal??
Didn't catch this sentence before but I would have to disagree. It may be more widely used, but it creates a larger load on the server which is what should be minimized whenever possible.

So to the best of my knowledge - especially if you have a heavy load on your site, you are better off causing the clients to do most of the work when you can which is what Javascript is good for.

Bilesveld, use php to help generate the links for each option, but don't use a header in the syntax you want...
The header that squeebee mentioned is best used for redirecting people who bookmarked a page previously to a new location or for redirecting people to your new site that was moved. Not for going to different places.

When I say use php to generate each option,
you would have the options group inside a while loop, I am assuming you have some sort of database to access for this? or if not we can work around that too. This should be your basic syntax:

<select name="Manu" size=".8" class="style12" id="Manu" onChange="if(this.options[this.selectedIndex].value!='$'){window.open(this.options[this.selectedIndex].value,'_self')}">
  while( $blah1 = $blah2){
     echo("<option value=\"http://www.turnthetides.com/Golf2/catalog.php?".$blah1."\">".$blah1."</option>");
   }
</select></td></tr>

$blah2 would generally be your db query, with mysql I have : $blah1=mysql_fetch_array($queryResult)
And that should get you a nice functionable setup where you have the code coing to the spaces you want and controlled by your database and so forth.

Its up to you on which code you choose, and I may not be understanding you correctly - but as I see it this is the code set up you are looking for.

Good luck and happy coding,
Red010Knight


0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 3

Expert Comment

by:red010knight
Comment Utility
If you are worried about javascript disabled browsers just add outside of the loop <input type="submit" value="Go"> and it could be a back up incase the onchange does not work which it should 9 times out of 10.

Red010Knight
0
 
LVL 17

Expert Comment

by:Squeebee
Comment Utility
Aah, now there is a good compromise. The use of both approaches ensures that those with Javascript lighten server load, while those without Javascript can still navigate the site.

And when I said more universal I mean more universally usable. I don't know of a browser out there that can't post a form, can't say the same for executing Javascript.
0
 
LVL 1

Author Comment

by:bliesveld
Comment Utility
I tried a simple implementation of you solution and this is what I get... No DB yet


http://216.120.247.146/~emerald/

any thoughts?
0
 
LVL 3

Expert Comment

by:red010knight
Comment Utility
can you post the php code you use there??

Otherwise I can't help with php errors

Red010Knight
0
 
LVL 1

Author Comment

by:bliesveld
Comment Utility
here it is, I was just testing it on one variable:


<?php
echo'<style type="text/css">
<!--
.style11 {
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 10px;
      color: #4D6185;
      font-weight: bold;
}
body {
      margin-left: 0px;
      margin-top: 0px;
      margin-right: 0px;
      margin-bottom: 0px;
}
.style12 {
      font-size: 9px;
      font-weight: bold;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      color: #4D6185;
}
.style13 {      font-size: 8px;
      font-weight: bold;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      color: #4D6185;
}
-->


 
 
  <table width="139" border="0">
    <tr>
      <td><span class="style12">Search Manufacturer</span></td>
    </tr>
    <tr>
      <td>
       <form>
        <select name="Manu" size=".8" class="style12" id="Manu" onChange="if(this.options[this.selectedIndex].value!='$'){window.open(this.options[this.selectedIndex].value,'_self')}">
        <option>Manufacturer</option>
        <option value=\"http://www.turnthetides.com/Golf2/catalog.php?".Calaway."\">".Calaway."</option>
        <option>Titleist</option>
        <option>TaylorMade</option>
        <option>Ping</option>
        <option>Mizuno</option>
        <option>Cobra</option>
        <option>Wilson</option>
        <option>Odyssey</option>
        <option>Teardrop</option>
        <option>Bettinardi</option>
        <option>Never Compromise</option>
        <option>See More</option>
        <option>Burton</option>
        <option>Belding</option>
        <option>Datrek</option>
        <option>Bennington</option>
        <option>Great Divider</option>
        <option>Foot Joy</option>
        <option>Dexter</option>
        <option>Nike</option>
        <option>Etonic</option>
        <option>Adidas</option>
        <option>Reebok</option>
        <option>Lady Fairway</option>
        <option>Jamie Sadock</option>
        <option>EP Pro</option>
        <option>Sport Haley</option>
        <option>Tail</option>
        <option>Tehama</option>
        <option>Zero Restriction</option>
        <option>Astra</option>
        <option>Ashworth</option>
        <option>Cutter &amp; Buck</option>
        <option>Polo</option>
        <option>Greg Norman</option>
        <option>Sports Haley</option>
      </select></td></tr></form>
       </td>
    </tr>
    <tr>
      <td height="14"> <strong class="style12"><span class="style12">Search</span> Categorie </strong> </td>
    </tr>
    <tr>
      <td height="14"><p class="style12">
        <form name=SearchCats method=POST action="">
        <select name="Cats" size=".8" class="style12">
          <option>Golf Clubs</option>
          <option>Putters</option>
          <option>Golf Bags</option>
          <option>Golf Shoes</option>
          <option>Ladies Apparel</option>
          <option>Mens Apparel</option>
        </select></td></tr></</form>
      </p>      </td>
    </tr>
  </table>';
?>
0
 
LVL 13

Accepted Solution

by:
lozloz earned 250 total points
Comment Utility
hi,

       <select name="Manu" size=".8" class="style12" id="Manu" onChange="if(this.options[this.selectedIndex].value!='$'){window.open(this.options[this.selectedIndex].value,'_self')}">

i don't get why you're echoing out all of this html. it would be much simpler if you didn't put the php tags in at all. i assume you're including this file on another page but that doesn't mean you need php tags. the error from the line above is due to your single quotes used for the echo function: it thinks that the single quote in the javascript is ending the echo function and so expects a semi colon, but there isn't one. so that's why the parse error crops up. if i were you, id' take out the php tags and echo function

cheers,

loz
0
 
LVL 3

Expert Comment

by:red010knight
Comment Utility
Basically what loz said, you need little if any section of that code in php. THe only part you need to be in php is:
   <form>
<?php //declare option variables
  $optionList=array('Manufacturer','Calaway', ...... and so forth till you have them all listed....);
?>
  <select name="Manu" size=".8" class="style12" id="Manu" onChange="if(this.options[this.selectedIndex].value!='$'){window.open(this.options[this.selectedIndex].value,'_self')}">
<?php
  for($i=0;$i<sizeof($optionList);$i++){
     echo ("<option value=\"http://www.turnthetides.com/Golf2/catalog.php?".$optionList[$i]."\">".$optionList[$i]."</option>");
   }
?>
</select>

And then the code should do what you want. This is the only part of that page that should have PHP in it. Everything else needs to be the same as if you were writing a straight HTML page.

Good Luck coding and have fun,
Red010Knight
0
 
LVL 3

Expert Comment

by:red010knight
Comment Utility
bliesveld,
Can you please explain to me the reasoning behind giving the points to Lozloz only and not to myself or squeebee who has been helping you for a countless amount of time? He answered one small question out of several we have done for you.

Though I am glad your code is working and things are better for you.

Red010Knight
0
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
i didn't really expect to get full points for this so if you want to dock and dish some out then feel free to get a mod to i suppose

loz
0
 
LVL 1

Author Comment

by:bliesveld
Comment Utility
pts for red010knight avaliable:
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now