Object Method error in IE only.

Discussion in 'JavaScript' started by chrisman826, Jul 22, 2007.

  1. #1
    Lil help is needed here.

    I have a object like this:

    
    function mediaObject(){
    	this.mediaItems = new Array();
    	this.count = 0;
    	this.id = 0;
    	
    	this.addMedia = function(data){
    		//alert("here");
    		var mediaType = data.mediaType.value;
    		var mediaLink = data.mediaLink.value;
    		var mediaCaption = data.mediaCaption.value;
    		var mediaImg;
                 ...etc
    	}
    ...etc
    }
    
    Code (javascript):
    And i have the object made like this
    
    var media = new mediaObject();
    
    Code (javascript):
    and i have a button like this (inside of a form of course)
    
    <input type='button' value='Add Media' onclick="media.addMedia(this.form);" />
    
    Code (markup):
    This works in Firefox, and produces no errors in the console,

    in Internet Explorer (7) on the other hand, i get the following error when i click on the button:
    Error:Object doesn't support this property or method

    I cant figure out what i have done wrong, or why this is even happening. I thought the error was deeper in the object, but after adding the alert, I find its crashing on the call to the method.

    Im not that great with OOP, But i have been working and learning a lot to utilize it. From what i know this should work, but it doesnt and I am not sure what I have wrong, but something must be!

    any help is greatly appreciated.
     
    chrisman826, Jul 22, 2007 IP
  2. ds316

    ds316 Peon

    Messages:
    154
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you give a full example of it I might be able to have a closer look at it. It's probably just IE being stupid (it does that sometimes).
     
    ds316, Jul 22, 2007 IP
  3. chrisman826

    chrisman826 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, IE is stupid. Im good now. thank you very much. I was able to get it working by making the button like so:

    
    <input type='button' value='Add Media' onclick="parent.media.addMedia(this.form);" />
    
    Code (markup):
    I added "parent" to the onclick method call. It really helps sometimes when u just throw up your hands and walk away for a few hours, then come back to your project and rethink.
     
    chrisman826, Jul 23, 2007 IP