#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    21

    Read php from javascript


    Hi guys

    I need your help. I am writing the list of code in my javascript and now I want to read my php code from my javascript using with loadjscssfile("test1.php", "js") function.

    Code:
    function loadjsfile(filename)
    
    {
    
        var fileref=document.createElement('script');
    
        fileref.setAttribute("type","text/javascript")
    
        fileref.setAttribute("src", filename);
    
        document.body.appendChild(fileref);
    
    }
    
    
    
    document.onkeydown = function(ev)
    
    {   
    
       var key;
    
       ev = ev || event;
    
       key = ev.keyCode;
    
       var image1 = document.getElementById("image1").getElementsByTagName("img")[0];
    
    
    
       if(key == 13)
    
       {
    
          if (img1.indexOf('image1_yellow.jpg') != -1)
    
          {
    
             if (img5.indexOf('picture1_yellow.jpg') != -1)
    
             {
    
                loadjscssfile("test1.php", "js");
    
             }
    
          }
    
       }
    Does anyone know how i can read my php code from javascript?
    Last edited by stephen100; March 25th, 2013 at 01:29 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,501
    Rep Power
    594
    That makes no sense. Why do you want to do that?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    21
    you don't understand what I am trying to achieve. I want to achieve is to read php in javascript when the image of picture1 is change it to picture1_yellow. I am using javascript to change the image when i press on the keyboard. Now I want to read php from javascript.

    See this code:
    Code:
        if (img1.indexOf('image1_yellow.jpg') != -1)
        {
           if (img5.indexOf('picture1_yellow.jpg') != -1)
           {
               loadjscssfile("test1.php", "js");
           }

    I am not really sure if it possible for php to detect the keycode that I press on it and when the image is change?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,501
    Rep Power
    594
    You do understand that PHP is server side and Javascript is client side, right? PHP is also stateless, once it has output the HTML to the browser, it knows nothing about what the browser is doing. PHP on the client side is useless. If you do need to communicate with the server via Javascript then you use Ajax.

    Comments on this post

    • ptr2void agrees : Once again, I am stunned.
    Last edited by gw1500se; March 25th, 2013 at 02:03 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    21
    Oh sorry I am not aware of it. I did not realised the difference between php and javascript. Do you know how php can detect on the keyboard when i press on the enter button and when the image is change then i do something?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,501
    Rep Power
    594
    Like I said, PHP knows nothing about what is happening on the client (browser) side, its gone.

    Perhaps if you explained better what you are trying to do we can suggest a solution.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    I strongly suggest getting a good book (or online tutorial) about the basics of HTTP, web servers, the different languages etc. Personally, I liked "HTTP: The Definite Guide", but it may be overkill for you.

    Doing "web programming" without understanding how it works is just pointless. Yeah, you might be able to copy and paste some stuff, but you'll stumble upon misunderstandings again and again.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo