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
https://forums.phpfreaks.com/topic/133774-solved-doesnt-work-in-ie/
Share on other sites

Don't have IE right now so can't test it but maybe its the ; character you need to remove or try #000000

 

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

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?

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 (:

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.