Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    93
    Thanks
    9
    Thanked 0 Times in 0 Posts

    IE onclick error with checkbox

    I'm having a problem in IE with adding onClick functionality to a checkbox. In Firefox everything works fine, no errors in Firebug. In IE, i get the error message "Invalid Property Value".

    Any ideas what the problem is in the following code? All other Javascript running on the page is working ok in both IE and Firefox, so it's only the onclick functions below causing the problem.

    event handler code..
    Code:
    function AttachEvent(obj,evt,fnc,useCapture){
    	if (!useCapture) useCapture=false;
    	if (obj.addEventListener){
    		obj.addEventListener(evt,fnc,useCapture);
    		return true;
    	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
    	else{
    		MyAttachEvent(obj,evt,fnc);
    		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
    	}
    } 
    //The following are for browsers like NS4 or IE5Mac which don't support either
    //attachEvent or addEventListener
    function MyAttachEvent(obj,evt,fnc){
    	if (!obj.myEvents) obj.myEvents={};
    	if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
    	var evts = obj.myEvents[evt];
    	evts[evts.length]=fnc;
    }
    function MyFireEvent(obj,evt){
    	if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
    	var evts = obj.myEvents[evt];
    	for (var i=0,len=evts.length;i<len;i++) evts[i]();
    }
    and my functions for adding onclick functionality to the checkbox...
    Code:
    function addOnClick () {
    	
    	var el = document.getElementById("journeyType");
    	el.onclick = function(){
              return disableDateField(el);
        };
    }
    
    function disableDateField (box) {
    	
    	var date_field = document.getElementById("return_date");
    	//check if checkbox is checked or not
    	if (box.checked == true) {
    		date_field.style.backgroundColor = "grey";
    		date_field.disabled = true;
    		
    	}
    	else {
    		date_field.style.backgroundColor = "white";
    		date_field.disabled = false;
    	}
    }
    
    AttachEvent(window,'load',init,false);
    AttachEvent(window,'load',addOnClick,true);

  • #2
    Regular Coder kosstr12's Avatar
    Join Date
    Apr 2007
    Location
    Woodstock, Georgia
    Posts
    428
    Thanks
    7
    Thanked 5 Times in 5 Posts
    Can we get a link to an example of the site where you're having the problems?

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    93
    Thanks
    9
    Thanked 0 Times in 0 Posts
    yep sorry i should have posted a link to start with, please excuse the messiness of the site (early stages!) - http://www.maguiresonline.co.uk/deve...***/index2.php

  • #4
    Regular Coder kosstr12's Avatar
    Join Date
    Apr 2007
    Location
    Woodstock, Georgia
    Posts
    428
    Thanks
    7
    Thanked 5 Times in 5 Posts
    Now I see what you're saying, I don't know how you could fix it though. I'm sure someone here can, Good Luck!


  •  

    Posting Permissions

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