SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2007
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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);
    the site (excuse the messiness, early stages) is at http://www.maguiresonline.co.uk/deve...ass/index2.php

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately web developers are forced to spell the American way so you'll have to change "grey" to "gray" ...
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2007
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i can't actually believe that was the problem, i've spent ages trying to work out what was going wrong! cheers jimmyp you're a legend

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    I should note that IE spells gray and lightgray differently.
    http://geek.co.il/wp/2008/02/02/web-site-design-crap
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •