Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Javascript and PHP problem

  1. #1
    Join Date
    Jan 2010
    Posts
    16

    Javascript and PHP problem

    I am working on my site which is utilizing PHP. I build pages as a template, using PHP includes for the header and footer, and testing on my local server. There seems to be some sort of problem with adding javascript to the site. Example - I am trying to add sexyCycle to feature content on my index page, but it won't load up. I have tested all my JS files in a plain html file and got sexyCycle working fine.

    Is there some sort of common issue here I need to work around? Is javascript just co***icting with PHP on my local server? please help!

  2. #2
    Join Date
    Mar 2010
    Location
    Ithaca, NY, USA
    Posts
    212
    JavaScript and PHP do not directly interact so that is not your problem.

    If you are using jquery/ajax to dynamically place content into your page and that content contains a script, it will not execute unless you explicitly tell it to.

    The way I do this, I would have a predefined function in my main js file (in your case it would be something like "startSexyCycle()") This function would be in a script that is in the dynamically loaded content like so:

    HTML Code:
    <div id="dynamicDiv">
      ...Content...
      <script type="text/javascript">
        startSexyCycle();
      </script>
      ...Content...
    </div>
    Once the content has been received and placed into the page by jquery/ajax, you would do this:

    Code:
      var scripts = document.getElementById("dynamicDiv").getElementsByTagName("script");
      for (var i = 0, i < scripts.length; i++)
        eval(scripts[i].innerHTML);



    If this isn't your problem, I would need to see some example code to figure it out.

  3. #3
    Join Date
    Jan 2010
    Posts
    16
    I wouldn't say im using jquery to place content into the page, I basically just have a unordered list of images, the sexycycle.js is just supposed to make them into a slideshow. I tested in an html file, worked fine, added the same thing to my php based site on my apache server and no go.

    The html for the images is like this...
    HTML Code:
    <div class="sexyCycle" id="box4">
    	<div class="sexyCycle-wrap">	
    		<ul class="sexyCycle-content">
    
    <li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/1.png"></li>
    <li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/2.png"></li>
    <li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/3.png"></li>
    <li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/4.png"></li>
    		</ul>
    	</div>
    </div>
    Those obviously are the images. The javascript files are placed in the header, with the core jquery 1.4, jquery.sexycycle, and an jquery.easing, which smooths the transitions.

    I also have this code in the header which activates
    HTML Code:
    <script type="text/javascript">
    		
    			
    // Initialize Home Feature Slideshow
    
    	$(document).ready(function() {
    	$("#box4").sexyCycle({
    			speed: 500,
    			interval: 4000
    		});
    	});
    						
    						
    	
    		</script>
    And this tiny bit of CSS:
    HTML Code:
    ul.sexyCycle-content  { list-style: none; margin: 0; padding: 0; width: 99999999; position: absolute }
    li.sexyCycle-content  { margin: 0; padding: 0; }
    .sexyCycle { position: relative; overflow: hidden; }
    .sexyCycle-wrap { position: relative; width: 99999px; }
    .sexyCycle-content { width: 99999; position: absolute; overflow: hidden; }
    #box4 {
    	height:480px;
    }
    Any ideas?

  4. #4
    Join Date
    Mar 2010
    Location
    Ithaca, NY, USA
    Posts
    212
    Well first off that css will not work properly because some of the width attributes just have numbers in them. Add 'px' to the end of any number and see if that fixes it... and on that note, am I right in assuming the 99999px thing is something that the script requires? If not, why not just do 100% or auto?

  5. #5
    heidner is offline New Member: Posts Will Be Moderated
    Join Date
    Feb 2011
    Posts
    1

    Unhappy Same problem!

    I am also trying to use sexyCycle within php includes, but having no luck. Any ideas why sexyCycle won't work within a php include?

    Edit: I noticed during first attempts of implementation that the css file the sexyCycle creator provides is a little sloppy and has some errors. I have already correct those. The new, pretty CSS file works with my HTML version.
    Last edited by heidner; 15 Feb 2011 at 05:09 PM. Reason: Adding additional information

  6. #6
    Join Date
    Mar 2011
    Posts
    18
    There is no much use for CSS here because the problem can be solved by a lot of numbers. Try to add px at the end of each number or you can just make it 100 percent.

  7. #7
    Join Date
    Jun 2007
    Posts
    295
    Do this: take the HTML only version of the page and the php version of the page and look at both source codes (after the php renders). This should give you a clue as to why the php version isn't working. Since php and javascript do not interact directly, maybe there is something in the php file that is rendering incorrectly and thus not allowing the javascript to run.

  8. #8
    Join Date
    Apr 2011
    Posts
    17
    CSS would not be very practical because there are figures to solve the issue through including px at the final of each figure or simply create it 100 percent.

  9. #9
    Join Date
    Sep 2011
    Posts
    19
    CSS is not at all useful here as there are different ways to solve the problem. You can try to add PX at the end of every number or just make it 100%.
    Last edited by andrewwhite345; 20 Sep 2011 at 01:30 AM.

  10. #10
    nakibfdc is offline New Member: Posts Will Be Moderated
    Join Date
    Sep 2011
    Posts
    1
    this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate a lot and never seem to get something done. Versatility is one of the benefits of a custom wedding dress, so you should make the most of it.


    Facebook Landing Page

  11. #11
    Join Date
    Sep 2011
    Posts
    17
    Very useful in order to solve the problem here as there is a number that the CSS will look to add a pixel or all numbers at the end there, but then it 100 percent.
    Last edited by darrensmith786; 26 Sep 2011 at 03:21 AM.

  12. #12
    harryraya is offline New Member: Posts Will Be Moderated
    Join Date
    Oct 2011
    Posts
    6
    Is there some sort of common issue here I need to work around?


  13. #13
    xuma's is offline New Member: Posts Will Be Moderated
    Join Date
    Nov 2011
    Posts
    8
    Is there some sort of common issue here I need to work around?


  14. #14
    Join Date
    Nov 2011
    Posts
    17
    This is really very valuable in order to crack the problem here as there is a quantity that the CSS will air to augment a pixel or all statistics at the finish there, but at that time it is at 100 percent.
    Last edited by carlhooper123; 16 Nov 2011 at 11:01 PM.

  15. #15
    Join Date
    Nov 2011
    Posts
    18
    Very useful in order to solve the problem here as there is a number that the CSS will look to add a pixel or all numbers at the end there, but then it 100 percent.
    Last edited by jacobmartin456; 14 Nov 2011 at 02:03 AM.

  16. #16
    Join Date
    Dec 2011
    Posts
    19
    CSS is not at all useful here as there are different ways to solve the problem. You can try to add PX at the end of every number or just make it 100%.
    Last edited by davidmorgan786; 19 Dec 2011 at 08:52 PM.

  17. #17
    Join Date
    Dec 2011
    Posts
    38
    Thanks ALJOHN for starting this thread. I now know what to do with my issue about Javascript and PHP. Thanks again!

  18. #18
    Join Date
    Dec 2011
    Posts
    1
    Said well, support you


    _________________
    Schaufensterpuppen

  19. #19
    Join Date
    Dec 2011
    Posts
    7
    very nice discussion this is,

    ----------------------
    Jonathanganesh
    Hire a php developer

  20. #20
    ronju is offline New Member: Posts Will Be Moderated
    Join Date
    Dec 2011
    Posts
    1

    Create A Server

    The key to any successful website is knowing your visitors. Site Analytics gives you the valuable, real-time data you need – information you can use to spotlight popular products, target new customers, track offer responses and much more. With over 30 detailed reports, you can find out where your visitors are coming from, what paths they take through your site, even where in the world they live.

    http://createaserver.com

Tags for this Thread

Posting Permissions

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