SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Funtion works in FireFox but not in IE

    Code:
    function showHideField(fieldId)
    {
    	var obj = getRefById(fieldId);
    	obj.style.display = (obj.style.display == 'none')?'inline':'none';
    	return true;
    }
    
    function getRefById(id)
    {
    	var ref = (document.getElementById)?document.getElementById(id):
    			((document.all)?document.all[id]:((document.layers)?document.layers[id]:null));
    	return ref;
    }
    I call it like

    <input type="checkbox" onchange="showHideField('field_id');">

    It works in FireFox but not in IE.
    ---------------------------
    Errors = Improved Programming.
    My Site

  2. #2
    SitePoint Member
    Join Date
    May 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you already try to put some debug code in 'getRefById'? Something like:

    Code:
    alert("Field type / name: " +
    	ref.nodeType + " / " +
    	ref.nodeName);
    return ref;
    Maybe you should add a test (temporary) for 'ref' being 'null' too...
    Last edited by vovtz; May 10, 2007 at 13:23. Reason: Clarifying what part is code

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it works fine. When I click in FireFox it shows the alert box.

    BUT, it doesn't do anything in IE??
    I noticed that if i check it and click REFRESH it then notices that it has been checked.

    is there issue where I have on Change() function??
    its like this

    HTML Code:
    		<input type="checkbox" name="template" value="0" class="checkbox" onChange="showHideField('select_template');" />
    ---------------------------
    Errors = Improved Programming.
    My Site

  4. #4
    SitePoint Member
    Join Date
    May 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana View Post
    is there issue where I have on Change() function??
    That might well be the cause of the problem, because for a checkbox its meaning seems a bit ambiguous (although the W3C might possibly have defined the behaviour quite rigidly, non-compliant browsers will always exist [and IE especially likes to be different ;( ]). For a 'text' input 'onchange' means something like "execute the code if the contents have changed when the focus goes away". But for a checkbox there are only 2 possible 'contents', on or off, so one might assume it to generate a 'onchange' event whenever clicked (as Fx does).

    Does the script fire in IE if you click the checkbox and then press <TAB>?

    Anyway, my guess is it'll work once you replace "onchange=" by "onclick=".

    Cheers, Vincent

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that was the problem.

    Thanks
    ---------------------------
    Errors = Improved Programming.
    My Site


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
  •