Results 1 to 7 of 7

Thread: Error in code

  1. #1
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Error in code

    I wasn't entirely sure where to put this but I figured html was general enough a place. I have an error in my code that I can't figure out. It works fine in firefox but it does not work in IE. I have copied all the related code below. The main objective of the code is to make a drop down menu choice change a picture elsewhere on the page.

    Error reads
    "Line 380
    Object doesn't support this property or method"
    Line 380 is the bracket "{" after the line "function imgswap()"


    <script type="text/javascript">
    /************************************************************
    * Script by : Raymond Angana
    * Title: Dropdown Based Picture w/ Captions
    * First seen in AFHB2000.com
    * rangana in AHFB2000.com
    * Created June 5, 2008
    * This notice must stay intact
    /**********************************************************/
    function imgswap()
    {
    bp=('http://xxxxx.xxx/'), //base url of your images
    imgnum=2, //Number of your images. This should match on your comboboxes options.
    thumb=document.getElementById('thumb'), //id of your image that will be changing
    combobox=document.getElementById('selection'); // id of your combobox.

    combobox.onchange=function()
    {
    thumb.src=bp+'picture'+this.value+'.jpg';
    description.innerHTML=caption[this.value];
    }
    }
    </script>

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    here is some changed up code. it might work:

    Code:
    <script type="text/javascript">
    /************************************************************
    * Script by : Raymond Angana
    * Title: Dropdown Based Picture w/ Captions
    * First seen in AFHB2000.com
    * rangana in AHFB2000.com
    * Created June 5, 2008
    * This notice must stay intact
    /**********************************************************/
    function imgswap()
    {
    bp=('http://xxxxx.xxx/'), //base url of your images
    imgnum=2, //Number of your images. This should match on your comboboxes options.
    thumb=document.getElementById('thumb'), //id of your image that will be changing
    combobox=document.getElementById('selection'); // id of your combobox.
    
    combobox.onchange=function()
    {
    thumb.src=bp+'picture'+this.value+'.jpg';
    document.getElementById('description').innerHTML=caption[this.value];
    };
    }
    </script>

  3. #3
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I tried the changes and got the same error. Tested it anyway and it still works in firefox but not in IE.

    here is some more code related to this function:

    I had to fix an earlier problem by putting the imgswap() into the onload of the body.

    <body class="thrColAbs" onload="MM_preloadImages('abouton.gif','teamon.gif','productson.gif','contacton.gif','forumon.gif','picture1.jpg','picture2.jpg'), imgswap()">


    and the drop down menu that changes it:

    <label>Select Color:</label>
    <select id="selection">
    <option value="1">Black</option>
    <option value="2">Pink</option>
    </select>


    and the picture that is being changed:

    <img src="http://xxxx.xxx/picture1.jpg" alt="brush" name="thumb" width="225" height="425" id="thumb">

    Thanks for trying to help

  4. #4
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Err, the name and username looks familiar

    Anyway, there's nothing wrong with the code, what's erroneous is this:
    Code:
    <body class="thrColAbs" onload="MM_preloadImages('abouton.gif','teamon.gif','productson.gif','contacton.gif','forumon.gif','picture1.jpg','picture2.jpg'), imgswap()">
    ...replace highlighted with semi-colon ( ; )


    You might also want to remove highlighted:
    Code:
    combobox.onchange=function()
    {
    thumb.src=bp+'picture'+this.value+'.jpg';
    description.innerHTML=caption[this.value];
    }
    It seemed to me that you are not using it (base on the markup provided)

    Hope that helps.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  5. #5
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    unfortunately the recommended changes did not seem to work

    I did preview it in IE (From dreamweaver) instead of just using IE tab and the error reads a little differently this way:

    instead of line 380 it states

    Line: 381
    Char: 2
    same error
    code: 0

    As for my username, i use it for everything - many message boards and games (so that may be the way you recognize it, in the event we have crossed paths in the past).

    Anyway, with your changes it does still work in firefox (I was wondering what that extra line of code did [and my saying is, if you do not know, leave it in]). The semi-colon change, similarly, seems to have changed nothing.

    Thank you for trying to help though

  6. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    I mean, that of the notice.

    Anyway, add highlighted:
    Code:
    var bp=('http://xxxxx.xxx/'), //base url of your images
    When you receive an error, try to remove that part I pointed out to you on post#4, unless you're using it in some special manner.

    Hope that helps.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  7. The Following User Says Thank You to rangana For This Useful Post:

    nibbon (10-08-2008)

  8. #7
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I love you, you did it, you are awesome

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
  •