Why is the text in input field not disappearing even after defining a function? The text is neither a placeholder of value. | SoloLearn: Learn to code for FREE!

+2

Why is the text in input field not disappearing even after defining a function? The text is neither a placeholder of value.

https://code.sololearn.com/Wqr7LFJ0ETJ3/?ref=app

5/17/2020 2:06:16 PM

Abhay Rao

16 Answers

New Answer

+2

I have set its display property to none when user gives input in email or password field but it's not happening.

+1

Fixed it ! Now check it.

+1

window.onload=function(){ document.getElementById('field').addEventListener("input",hideText); function hideText(){ document.getElementsByClassName('email_placeholder')[0].style.display="none"; document.getElementsByClassName('pass_placeholder')[0].style.display="none"; } }

+1

Is window.onload necessary and why did you add indexes ?

+1

it was ClassName ,also it was email not mail and also it was ElementsbyClassName not Element since it is use to get an array of classes with same name so you need to use [0] to tell the index of which class you are talking about so I hope you have a clear understanding of why I included indexes about window.onload it stops the JavaScript to get loaded before html ,try removing it and you will see some errors

+1

What if I have to disappear text of a particular field in which the input has been give and is window.onload necessary ?

+1

Then you have to add two different input functions with different id or class name ,here you are using just one input for both with same id ,

+1

Is window.onload necessary ?

+1

I already told about window.onload function ,if you wanna remove you can ,but js might get loaded before html and it will give errors since JavaScript will try to get the elements which doesn't exist yet

+1

Why is the border property not applying in JS ?

+1

wrong class name ,check the spelling of email ,also ElementsbyClassName means it returns an array you need to specify which class you wanna get from it ,use indexing for that as I already told above

0

You are saying it isn't a placeholder of that input box as it is ,so why should it disappear ,it's just a div with text in input box

0

I don't see any display:none ,maybe you forgot to add JavaScript

0

i dont see

0

0