Can you Embed Java in php?

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>';
?>
LVL 1
bliesveldAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mattjp88Commented:
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
aolXFTCommented:
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
bliesveldAuthor Commented:
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.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

SqueebeeCommented:
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.
red010knightCommented:
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
bliesveldAuthor Commented:
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.
SqueebeeCommented:
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();
red010knightCommented:
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
SqueebeeCommented:
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?
red010knightCommented:
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


red010knightCommented:
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
SqueebeeCommented:
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.
bliesveldAuthor Commented:
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?
red010knightCommented:
can you post the php code you use there??

Otherwise I can't help with php errors

Red010Knight
bliesveldAuthor Commented:
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>';
?>
lozlozCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
red010knightCommented:
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
red010knightCommented:
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
lozlozCommented:
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
bliesveldAuthor Commented:
pts for red010knight avaliable:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.