HIII
IAM FACING THE TROUBLE OF ASIGNING APHP VARIBALE TO A JAVA ONE MY CODE IS BELOW PLS HELP ME
<script type="text/javascript">
function test(imageam)
{

 var id = imageam;
document.getElementById('element').src ='<?php echo $dirname ; ?>';+id;

}

</script>
AND THE VARIABLE $dirname contains image drectory which was mentioned in my php code

    For one, you should fix the Shift/Caps Lock key on your keyboard, BECAUSE TYPING A POST IN ALL CAPS IS LIKE SHOUTING, which is quite rude. You might want to look into a spell-checker or two as well.

    For your actual issue, what does the output of that code look like if you view the source in your browser? Assuming that the PHP variable exists and has data (do you even check for this?), note that your Javascript (which, by the way, is not the same as Java) would look something like this:

    document.getElementById('element').src ='foobar';+id;

    Notice the syntax error? (Hint: You've got an extra semicolon in there that doesn't belong.)

      amsimaganti;10983342 wrote:
          function test(imageam)
           {
      
       var id = imageam;
      document.getElementById('element').src ='<?php echo $dirname ; ?>'[B][COLOR="Red"];[/COLOR][/B]+id;
      
      }

      I'd need to see more of your code. just keep in mind that javascript and php cannot work together directly: php goes first (writes the html and javascript), and then it's done. javascript runs after.

      incidentally, why do you have an extra semicolon (highlighted) in there? might that be part of your problem?

        <html>
        <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
        <script type="text/javascript">
        function test(imageam)
        {
        
         var id = imageam;
        document.getElementById('element').src =  "<?php echo '$dirname'?>"+id;
        ?>
        " +id;
        
        }
        
        </script>
        <?php include 'popup.php' ?> 
        
        </head>
          <body>
           <?php 
              include 'index.php';
              $dirname = "./images/smileys/happysmileys/hs1";	
              if(isset($_REQUEST['hs1']))
              {
               $dirname = "./images/smileys/happysmileys/hs1";
              }
              if(isset($_REQUEST['hs2']))
        {
        $dirname = "./images/smileys/happysmileys/hs2";
        }
        if(isset($_REQUEST['hs3']))
        {
        $dirname = "./images/smileys/happysmileys/hs3";
        }
        $images = scandir($dirname);
        $ignore = Array(".", "..");
        foreach($images as $curimg){
        if(!in_array($curimg, $ignore)) {
        ?>
        <div style="border: 1px solid #ff0000 ;background: #ffffff ;width:170px;height:170px;padding: 5px;float:left ">
        <?php
        if(isset($_REQUEST['happy']))
        {
        
        echo "<a href='#dialog' onclick=test('$curimg') name='modal'>  <img src='./images/smileys/happysmileys/hs1/$curimg'  height='170' width='170' align='center'></img></a>";
        
        }
        if(isset($_REQUEST['hs1']))
        {
        echo "<a href='#dialog' onclick=test('$curimg') name='modal'>  <img src='./images/smileys/happysmileys/hs1/$curimg'  height='170' width='170' align='center'></img></a>";
        }
        if(isset($_REQUEST['hs2']))
        {
        echo "<a href='#dialog' onclick=test('$curimg') name='modal'>  <img src='./images/smileys/happysmileys/hs2/$curimg'  height='170' width='170' align='center'></img></a>";
        }
        if(isset($_REQUEST['hs3']))
        {
        echo "<img src='./images/smileys/happysmileys/hs3/$curimg' height='170' width='170'/>";
        }
        
        ?>
        </div>
        <?php 
        };
        }
        
        
        
        
        
        ?>
        <div id="boxes">
        
        <div id="dialog" class="window" >
        <div align="right" style="vertical-align: top">
        
        <a href="#"class="close"/>Close it</a>
        </div>
         <div align="center" >
         <a> 
        
         <img  id = "element" height="160" width="160" align="center"></img>
        </a>
        </div>
        
        </div>
        <div id="mask"  >
        </div>
        
        
        
        <table align="right" style="vertical-align: bottom" >
        <tr>
        
        <td align="right" >
        
        <form action="happy.php" method="post">
        
        PAGES:<input type="submit" name="hs1" value="1">|
        <input type="submit" name="hs2" value="2">|
        <input type="submit" name="hs3" value="3">|
        
        </form>
        </td>
        </tr>
        </table>
        <body>
        <html>

        this my entire code used to display the images from difrent dirctories and afer an image is cilcked a code was return using jquery to display the popup
        the function test iamge is writen to get the id of the iamge that was clicked and then placing the inage onthe popup
        as the directory name is chaging dinamicaly which is placed in $dirname
        how can asign that php variable containg image path in my function
        thanks in advance

          When posting PHP code, please use the board's [noparse]

          ..

          [/noparse] bbcode tags as the make your code much easier to read and analyze.

          As for your issues, you're attempting to output $dirname before you define it.

            bradgrafelman;10983575 wrote:

            When posting PHP code, please use the board's [noparse]

            ..

            [/noparse] bbcode tags as the make your code much easier to read and analyze.

            As for your issues, you're attempting to output $dirname before you define it.

             its mentioned in the bellow php code $dirname contains  path of the image directory
              amsimaganti;10983666 wrote:

              $dirname contains path of the image directory

              No, it does not; at the point where you attempt to echo its contents out, it doesn't contain anything because it doesn't even exist. It is defined after that point of the code. You can't put the cart before the horse, you see.

              Also, note on the manual page for [man]string[/man] the difference between using single quotes and double quotes (or no quotes at all if you're just referencing a variable and nothing else).

              This:

              $msg = 'Hello World!';
              echo '$msg';

              will output a dollar sign follow by the letters 'm', 's', and 'g'.

                Write a Reply...