Java - PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dujmovicv
    New Member
    • Jul 2006
    • 10

    Java - PHP

    Hello, I'm new in both Java and PHP and I'm trying to build a drop down menu with options for language select for a web site. I.E. :

    <select onchange="windo w.location='wha tever.php?langu age='+this.valu e">
    <option value="eng" <?if ($language == "eng") {?>selected<?}? >>English</option>
    <option value="ger" <?if ($language == "ger") {?>selected<?}? >>German</option>
    </select>

    I wonder if the selected option value can call a javascript or some function which will display the dynamic menu as well (*.gif buttons in JavaScript with onMouseover event, for example...)

    Please HELP!
    Thanks
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    thats the code i gave you in the php section :P yes it can try it out and i can help you with your code when you get stuck -- look at onchange event and make it call a javascript function in that function do whatever.

    Comment

    • dujmovicv
      New Member
      • Jul 2006
      • 10

      #3
      Originally posted by iam_clint
      thats the code i gave you in the php section :P yes it can try it out and i can help you with your code when you get stuck -- look at onchange event and make it call a javascript function in that function do whatever.

      Hello iam_clint!

      I'm back again with my probleme....

      So, as I mentioned I've tried to combine php and java to build a dynamic menu with select form. Here is my code (example), I wonder if I'm going on the right way....
      Please help if U have some good ideas... ;-)

      <script language="JavaS cript">

      function jumpmenu(selLan g)
      {
      var s = selLang;
      echo "<img src=$s.gif>";
      }

      </script>

      <?
      print <<<HERE
      <select name="select" onchange="jumpm enu(this)">
      <option value="1" selected>Srpski </option>
      <option value="2">Magya r</option>
      <option value="3">Engli sh</option>
      <option value="4">Deuts ch</option>
      </select>
      HERE;
      ?>

      As you can suppose it doesn't works...

      Comment

      • iam_clint
        Recognized Expert Top Contributor
        • Jul 2006
        • 1207

        #4
        Code:
        <script language="JavaScript">
        function jumpmenu(selLang) {
           var s = selLang;
           document.write("<img src="+s+".gif>");
        }
        </script>
        Your first problem was you were doing php type code in your javascript
        Code:
        <select name="select" onchange="jumpmenu(this.value);">
        <option value="1" selected>Srpski</option>
        <option value="2">Magyar</option>
        <option value="3">English</option>
        <option value="4">Deutsch</option>
        </select>
        Your second problem was jumpmenu(this) needed to be jumpmenu(this.v alue);
        why even have your php code print that, its a static select menu. that should fix your problems that i seen so far.

        Comment

        • dujmovicv
          New Member
          • Jul 2006
          • 10

          #5
          I managed to echo a select drop-down menu with 4 languages with an array:
          [php]
          <?php
          $language = $_GET["language"];
          ?>
          <select onchange="windo w.location='sel ect.php?languag e='+this.value" >
          <?php
          $language = array(
          "",
          "English",
          "Deutsch",
          "Magyar",
          "Srpski");
          for ($i = 1; $i <= 4; $i++)
          {
          print "<option value=$i>$langu age[$i]</option>";
          print "<h3>Langua ge is : $language[$i]</h3>";
          }
          ?>
          </select>
          [/php]

          I can't see my mistake : in the select field always stays "English" and don't change to the selecteg language... The other question: the script doesn't prints the text in <h3> tag. Why is that?

          Comment

          Working...