Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts

    need help with if statement

    I am trying to check for a javascript condition and then depending on that execute a php code. My code:


    Code:
    <script>
    var temp = 'wtf';
    
    if(temp != 'wtf')    {
         <?php
         $some = 'xxx';
         ?>
    }
    </script>
    so i quickly learned that the php code will be executed regardless whether or not the javascript condition is met. is there a way to work around this? maybe someone can show me how to pass strings from javascript to php without forms.... thanks a lot.

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    You'll have to use an AJAX request. You will still have your if statement but inside will be an AJAX function that will retrieve the information from a php page.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    can you provide me with sample code? thanks.

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    anyone? project is due tomorrow at 1pm. procrastination is a killer.....

  • #5
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Code:
    function ajaxFunction()
    {
    function getInfo(){
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
     }
     xmlHttp.open('GET','page url',true);
     xmlHttp.send(null);
     if(xmlHttp.readyState == 4){
         //what you want it to do with the response goes here
     }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •