Advanced Search

Results 1 to 4 of 4

Thread: Object cannot be extended in IE - Object does not support this property or method

  1. #1
    Join Date
    Jan 2007
    Location
    Chennai, Tamil Nadu, India
    Posts
    31
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Object cannot be extended in IE - Object does not support this property or method

    Code:
    <script>
    	onerror = function(a,b,c) { alert(a+c) }
    </script>
    
    <script type="text/javascript">
    	function _isEmail() 
    	{
    	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    	   if( reg.test(this.value) )
    	   	alert("yes")
    	else
    		alert("no")
    	}
    
    	Object.prototype.isEmail = _isEmail
    
    </script>
    
    <input type="text" name="email" id="email" value="sdf@sdf.com" />
    
    <script>
    	document.getElementById('email').isEmail()
    </script>
    the above code works well in firefox but not in IE6 or IE7 and i didn't check it in IE8...

    i am trying to extend the Object type to add this isEmail method

    so that i can call this function on any object like input elements...
    since all the elements are basically of the type Object it should work and it works in FF... is there any frame work to do this... what about prototype.org... ???

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    In IE the prototype object of system defined objects are not accessible or thus can't be extended..

  3. The Following User Says Thank You to codeexploiter For This Useful Post:

    jayapalchandran (03-13-2009)

  4. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,690
    Thanks
    43
    Thanked 3,129 Times in 3,095 Posts
    Blog Entries
    12

    Default

    I think that all of the popular javascript libraries have methods for creating extensible pseudo classes that are objects. How this is done in each varies, but for what you want, there is probably already a built in extension that would serve well enough. I'm most familiar with jQuery. In it you may obtain a jQuery object reference to your example input like so:

    Code:
    $('#email')
    That actually returns an array, but since the selector is an id, if your HTML code is valid, it will be an array of one object, the input in question. You may use jQuery's each to iterate that array using your _isEmail function - probably without modification, ex:

    Code:
    $('#email').each(_isEmail);
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    jayapalchandran (03-13-2009)

  6. #4
    Join Date
    Jan 2007
    Location
    Chennai, Tamil Nadu, India
    Posts
    31
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default that coule be nice

    thank you all. anyway i was thinking about the ff style of prototype. hope we have to wait for IE to change... which is ...

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
  •