phil88 Posted November 22, 2008 Share Posted November 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted November 22, 2008 Share Posted November 22, 2008 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'); } Quote Link to comment Share on other sites More sharing options...
phil88 Posted November 22, 2008 Author Share Posted November 22, 2008 Made no difference unfortunately Thanks anyway. Quote Link to comment Share on other sites More sharing options...
phil88 Posted November 23, 2008 Author Share Posted November 23, 2008 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? Quote Link to comment Share on other sites More sharing options...
php_tom Posted November 23, 2008 Share Posted November 23, 2008 does document.getElementById(id).style.color='#000;'; work? Quote Link to comment Share on other sites More sharing options...
phil88 Posted November 23, 2008 Author Share Posted November 23, 2008 No, that breaks the colour changing in other browsers too. Quote Link to comment Share on other sites More sharing options...
phil88 Posted November 23, 2008 Author Share Posted November 23, 2008 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 (: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.