Results 1 to 3 of 3

Thread: Javascript Control Php Display

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default Javascript Control Php Display

    Is there a way to have a javascript value control which php is displayed? For example I'm trying to use an increasing javascript variable to control which php array value is displayed.

    Code:
    var x = 0;
          while ( x < <?php echo $Total; ?> ) {
          var address = "<?php echo $Name[?>x<?php ];?>>";
          x++;
    }
    So it would go be to the php as something like this in the end

    Code:
    var x = 0;
    // x=0
          while ( 0 < 5 ) {
          var address = "<?php echo $Name[0];?>";
          x++;
    
    //x = 1
          var address = "<?php echo $Name[1];?>";
          x++;
    // ETC.
    }
    and on the actual page

    Code:
    var x = 0;
    // x=0
          while ( 0 < 5 ) {
          var address = "22 main street city, state, country";
          x++;
    
    //x = 1
          var address = "23 different street city, state, country";
          x++;
    // ETC.
    }

  2. #2
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    yup... i believe all you need to do is save the file with a PHP extension as opposed to HTML (or JS) and then it should work... i did something similar to this on a contact form... theres an ajax thank you message that i wanted to be editable via the content management database, so i used that little trick...
    Second Link is the one you want

  3. The Following User Says Thank You to thenajsays For This Useful Post:

    bluewalrus (09-16-2009)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I actually had to go about creating the same process in php that I did in javascript so the page wouldnt have to be reloaded again as the php was being processed first.

Bookmarks

Posting Permissions

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