Jump to content

[SOLVED] Doesn't work in IE


phil88

Recommended Posts

I have a simple javascript function that will clear the contents of a input box and change the colour of the text from grey to black, it's called when the input box is clicked.

 

It works 100% as intended in Firefox, Opera and Chrome, but in IE, the contents of the input box is cleared, as it should be, but the text remains grey. Also, if I click off of the text box, then back into it, it gets cleared again - this doesn't happen in the other browsers.

 

Here's my code;

    function clearBox(id){
            document.getElementById(id).setAttribute('value','');
            document.getElementById(id).setAttribute('style','color: #000;');
    }

 

Can anybody shed some light as to what's going wrong? It makes sense that every time it's clicked the box is cleared, but none of the other browsers do that, which is a good thing.

Link to comment
Share on other sites

Ok, I've managed to fix IE's problem of re-clearing the input box on every click instead of just the first by using a simple boolean flag;

    var flag = true;
    function clearBox(id){
        if(flag){
            document.getElementById(id).setAttribute('value','');
            document.getElementById(id).setAttribute('style','color: #000000');
            flag = false;
        }
    }

 

I'm still having issues with the colour not being changed correctly in IE, anybody know what I'm doing wrong, or what the issue is?

Link to comment
Share on other sites

I managed to fix it, I just used a totally different method of changing the font colour and made a new CSS class with black text for the input box and changed it in the input box's onclick attribute with:

this.className='activated'

 

Thanks for your help though (:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.