SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy My Javascript functions don't work in IE7

    If you have IE7 installed, please take a look at my latest project. Click on one of the input fields on the sidebar. The default value should disappear the moment you click on it, however it seems in IE7 this doesn't work at all. There are a few other Javascript functions on the site that also don't work and I seriously wonder why. What am I missing?

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried it and it's working in ie7. ???

  3. #3
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's weird! I tried it at my friend's PC and it didn't work, even though he has Javascript enabled. Anybody else?

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pixelateur View Post
    If you have IE7 installed, please take a look at my latest project. Click on one of the input fields on the sidebar. The default value should disappear the moment you click on it, however it seems in IE7 this doesn't work at all. There are a few other Javascript functions on the site that also don't work and I seriously wonder why. What am I missing?
    Your friend's I.E. may have JS disabled only for the internet zone.

    A friendlier algorithm for the onfocus handler would be:
    Code:
    if(this.value==this.defaultValue)
     this.value='';
    Combined with this onblur handler:
    Code:
    if(this.value=='')
     this.value=this.defaultValue;
    Tab-indentation is a crime against humanity.

  5. #5
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, sorry for being such a noob but where exactly would you put that code.

    My current one is this:
    Code:
    window.onload = function() {
      document.getElementById('user_name').onfocus = function() {
        this.value = '';
      }
    	document.getElementById('user_password').onfocus = function() {
        this.value = '';
      }
    	document.getElementById('abonnent').onfocus = function() {
        this.value = '';
      }
    	document.getElementById('freund').onfocus = function() {
        this.value = '';
      }
    
    }

  6. #6
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pixelateur View Post
    OK, sorry for being such a noob but where exactly would you put that code?
    Just place this anywhere below your form(s). It will run on anything, and assumes that you don't use the onfocus or onblur events of form elements for anything else.

    Code:
    <script type='text/javascript'>
    /*73637269707465726C61746976652E636F6D*/
    
    for(var i=0, df=document.forms, len=df.length; i<len; i++)
     for(var j=0, et, elems=df[i].elements, el=elems.length; j<el; j++)
      if( (et=elems[j].type) && /text|textarea|password/.test(et) )
       {
        elems[j].onfocus=function(){if(this.value==this.defaultValue)this.value='';}
        elems[j].onblur=function(){if(this.value=='')this.value=this.defaultValue;}
       }
    
    </script>
    Tab-indentation is a crime against humanity.

  7. #7
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, great, thanks!


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
  •