www.webdeveloper.com
Results 1 to 14 of 14

Thread: Javascript not working in IE

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    7

    Thumbs up Javascript not working in IE

    I write javascript for image slide show.

    Code:
    		var mygallery=new fadeSlideShow({
    			wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    			dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
    			imagearray: [<?php $q2 = mysql_query("select * from home_flash");
    						$i = 0;
    						while($res = mysql_fetch_array($q2))
    						{
    							$image[$i] 	= $res[1];
    							$text[$i] 	= $res[2];
    							$str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],";
    							echo $str;
    							$i++; 
    						} ?>
    
    		//<--no trailing comma after very last image element!
    			],
    			displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
    			persist: false, //remember last viewed slide and recall within same session?
    			fadeduration: 500, //transition duration (milliseconds)
    			descreveal: "always",
    			togglerid: ""
    		})
    In IE I got an error

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2)
    Timestamp: Sat, 20 Mar 2010 06:22:10 UTC

    Message: 'imagearray[...].0' is null or not an object
    Line: 37
    Char: 3
    Code: 0
    URI: http://localhost/baei/scripts/fadeslideshow.js
    If you have solution for thi, then please help with it!

    Thanks for your precious time.

    Cheers!!

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    The error message is telling you that your imagearray[] has not been initialised and the reason for that is because you cannot have php code mixed in with javascript as in:

    Code:
    var mygallery=new fadeSlideShow({
    wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
    imagearray: [<?php $q2 = mysql_query("select * from home_flash");
    $i = 0;
    while($res = mysql_fetch_array($q2))
    {
    $image[$i] = $res[1];
    $text[$i] = $res[2];
    $str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],";
    echo $str;
    $i++; 
    } ?>
    
    //<--no trailing comma after very last image element!
    ],
    You can have php embedded in html code though. PHP code is a server side scripting language and so is executed on the server before the ouput html is sent back to the browser. PHP does not go through javascript looking for php code to execute.

    When the html is received by the browser, then the javascript is executed.

    If you want to execute php code from javascript you have to use AJAX.
    Last edited by tirna; 03-20-2010 at 04:03 AM.

  3. #3
    Join Date
    Mar 2010
    Posts
    7

    Thumbs up

    hey tirna,

    thanks for your reply. I know what you talking about. So how can this code worked in firefox, chrome, safari, etc.

    This code is not worked in IE only,so if you have any thougts on this than please tell me, so I can remove that bug.

    Cheers!!!

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    no prob jkhavefun

    If it's working in other browsers then please disregard my earlier post. I was always under the impression that you couldn't mix PHP and javascript.

    I've never had to mix php and javascript before.

    Well, you learn something new every day. As they say in the classics, you're never too old to stop learning
    Last edited by tirna; 03-20-2010 at 04:21 AM.

  5. #5
    Join Date
    Mar 2010
    Posts
    7

    Thumbs up

    dont worry a all

  6. #6
    Join Date
    Mar 2010
    Posts
    7
    Hi, fang

    Code:
    AddType application/x-httpd-php .js
    I add that but, it does not make any difference. If I miss something then please draw my attention toward that.

    Cheers!!!

  7. #7
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    because you cannot have php code mixed in with javascript
    Yes you can. Any file type can be parsed as php on the server.
    The php in the script is writing content to a json notation.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  8. #8
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    I was always under the impression that you couldn't mix PHP and javascript
    Add this to .htaccess
    Code:
    AddType application/x-httpd-php .js
    At least 98% of internet users' DNA is identical to that of chimpanzees

  9. #9
    Join Date
    Jan 2009
    Posts
    18
    Code:
    		var mygallery=new fadeSlideShow({
    			wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    			dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
    			imagearray: [<?php $q2 = mysql_query("select * from home_flash");
    						$i = 0;
    						while($res = mysql_fetch_array($q2))
    						{
    							$image[$i] 	= $res[1];
    							$text[$i] 	= $res[2];
    							$str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],";
    							echo $str;
    							$i++; 
    						} ?>
    
    		//<--no trailing comma after very last image element! (Are you sure theres no trailing comma)
    			],
    			displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
    			persist: false, //remember last viewed slide and recall within same session?
    			fadeduration: 500, //transition duration (milliseconds)
    			descreveal: "always",
    			togglerid: ""
    		})


    commas in json objects can be a trick to javascript when we deal with the browser.

    Watch for this kind of error many of js programmers suffer.

    Let me give you an example:

    Code:
    //this will work on FF browser while not with IE
    var obj= {
      key: "Some Value", //notice the comma here
    };
    
    alert (obj. key);

  10. #10
    Join Date
    Mar 2010
    Posts
    7
    hi zidaine_38,

    Nice explanation from you mate. But what about it working on IE? I done lot to solve it but I cant. I think this is because today is weekend? lol

    I have no answers yet to solve it!

    Cheers!!!

  11. #11
    Join Date
    Jan 2009
    Posts
    18
    You must change the source code...

    Code:
    var mygallery=new fadeSlideShow({
    wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
    imagearray: [<?php $q2 = mysql_query("select * from home_flash");
    $i = 0;
    while($res = mysql_fetch_array($q2))
    {
    $image[$i] = $res[1];
    $text[$i] = $res[2];
    $str = "['images/fla/".$image[$i]."','','','".$text[$i]."'],"; //here!!! Notice the comma at the end!
    echo $str;
    $i++; 
    } ?>
    
    //<--no trailing comma after very last image element!
    ],

    It should be like this:

    Code:
    var mygallery=new fadeSlideShow({
    wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    dimensions: [380, 469], //width/height of gallery in pixels. Should reflect dimensions of largest image
    imagearray: [<?php $q2 = mysql_query("select * from home_flash");
    $i = 0;
    //initialize the $image and $text here, and also $str
    $image= array (); $text= array  (); $str= ""; //for strict compliance
    while($res = mysql_fetch_array($q2))
    {
    $image[$i] = $res[1];
    $text[$i] = $res[2];
    $str .= ($str!== ""? ",": ""). "['images/fla/".$image[$i]."','','','".$text[$i]."']"; //remove the comma here at the end and put a logical condition to check where the commas should be placed
    $i++; 
    } 
    echo $str;
    ?>
    
    //<--no trailing comma after very last image element!
    ],
    Last edited by zidaine_38; 03-20-2010 at 06:01 AM. Reason: Forgot to echo the string! heheh

  12. #12
    Join Date
    Mar 2010
    Posts
    7

    Thumbs up Whoola

    Hey zidaine_38,

    Many Many thanks!!

    It's working mate, thanks for tour help!

  13. #13
    Join Date
    Nov 2010
    Posts
    1
    [COLOR="Red"]Great answer! Can you also help me with my script? I am having the same problem and can't find which comma to delete or a way to correct it. My script reads as follows:

    <html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="https://files.me.com/tfwn93/flykz7">

    /***********************************************
    * Ultimate Fade In Slideshow v2.0- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
    ***********************************************/
    </script>
    <script type="text/javascript">

    var mygallery=new fadeSlideShow({
    wrapperid: "fadeshow1",
    dimensions: [780, 180],
    imagearray: [
    ["https://files.me.com/tfwn93/y84lqh", "http://web.me.com/tfwn93/elixsys/Technology.html", "_top", ""],
    ["https://files.me.com/tfwn93/3zs7s9", "http://web.me.com/tfwn93/elixsys/Team.html", "_top", ""],
    ["https://files.me.com/tfwn93/kjg79d", "http://web.me.com/tfwn93/elixsys/Market.html", "_top", ""],
    ["https://files.me.com/tfwn93/16lh4b", "http://web.me.com/tfwn93/elixsys/Mission.html", "_top", ""],
    ],
    displaymode: {type:'auto', pause:4000, cycles:0, wraparound:false, randomize:true},
    persist: false,
    fadeduration: 700,
    descreveal: "ondemand",
    togglerid: ""
    })

    </script>
    </head>
    <body>
    <div id="fadeshow1"></div>
    </body>
    </html>

  14. #14
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    imagearray: [
    ["https://files.me.com/tfwn93/y84lqh", "http://web.me.com/tfwn93/elixsys/Technology.html", "_top", ""],
    ["https://files.me.com/tfwn93/3zs7s9", "http://web.me.com/tfwn93/elixsys/Team.html", "_top", ""],
    ["https://files.me.com/tfwn93/kjg79d", "http://web.me.com/tfwn93/elixsys/Market.html", "_top", ""],
    ["https://files.me.com/tfwn93/16lh4b", "http://web.me.com/tfwn93/elixsys/Mission.html", "_top", ""],
    ],
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles