Hello
Today I created a Amazing Clear Input with HTML & JS. This is simple placeholder input I use JavaScript to clear input you can be also a...
For further actions, you may consider blocking this person and/or reporting abuse
Did you know there is an
<input type=“search” />
for stuff like this? I think it even has decent browser support.Hello,
type="search" is for search, not for the ability to clean the input. Using it for an username, except if it's for search an username, is not a good practice. This could involve side effects in the future. Moreover Firefox Desktop doesn't seem to display the cross.
To OP, you have an error in your HTML : type=“search" the first quotes are invalid, curly quotes instead of straight quotes
Good point! I think you’re right.
I actually first using simple type="text" but kyle suggest me to use type="search"
Yes I know about that but I forgot to use 😅 and i use some of code from my previous post
Well, as with everything... it has trade offs.
With your approach you get full control over the design of the “x”, but it requires JS and you need to use care to make sure it remains accessible.
With
<input type=“search” />
you can’t change the look of the “x”, but it will match their OS, which could be desirable! It also won’t require JS to function and should be accessible.I updated my code 😃
If this was in a form element the x could actually be a button or input with type=“reset” which clears the inputs of a form natively and is accessible by default. No need to build that part yourself in js.
developer.mozilla.org/en-US/docs/W...
But reset is use for full form or input what if you only want to use for certain field
That’s a good point! In that case what you demonstrated would be the way to go 😄
There are many ways but I written a beginner friendly
But what does this search for? I would like to be able to search inside a page I had online of my own making so this sounds goods yet I do not no the parameters from this code of what or where is looks or reveals the answer.
Mention is made of beginners just doing a copy and paste but to me this is just a box that looks like it should do something but no explanation of what it does more than the very large promise of search de facto owt.
Hey I understand but now I explain the codes in my new post and this post is only have a clear functionality with HTML and javascript so if user want to clear the input so with that button user can clear the input
img class could be more meaningful as that’s not an image so could be cross or icon or something more meaningful
JS need some optimisation as it’s targeting body, it should target form and some more JS logics can be improved
I know you are just sharing the idea, idea is good. Think of beginners who are just gonna copy paste your code.
Thanks I take care of that from next post
Here's another tip:
Nah just do this ☺️
Nice ❤️
Thank you 😊
👍
Here's a nice tip, because .length 0 or -1 are falsey, you don't need to check if less than or equal to 0, just if truethy or falsely
Thank you 😊 Very nice tips