Is there a simple way possibly using jquery and css to make an x appear in every input type search field, and when its clicked it clears the text that’s been typed.
This for example is a a text field on one page thats type is set to search.
So what Im trying to do is ideally when they start typing a little ‘x’ appears on the right side, and when its clicked it clears all the text that the user has already typed in.
Its not ideally what i wanted to do, as I have to add the span to each input field, which isn’t the best option really, ideally I need the x to identify where an input field is and attach itself to it, and then when they start typing it appears for the user to click and clear the text.
But because I havent got a wrapper div around these two, the span shoots off to the right of the page, but the action of starting to type and then it appears works. Just not ideal, and a bit amateur really.
Hi coothead, sorry wasn’t putting down what you posted as yes that clear button would be great in some cases on our pages there multiple search boxes, and the button to the right wouldnt fit, so am going to have to go with it appearing inside the text box. And thats why I want to use ‘this’ to know which button was clicked inside what text box to only clear the text inside that textbox, not all of them.
Its not a parent so I assume this.prev(‘textBox’) would suffice.
It’s not a mobile issue as such because most browsers are now adding the cross and clearing text automatically when input type=search is used. You should just use type=“text” instead to avoid any confusion.
As coothead said most times these form elements are best left alone. If you simply used input type=“search” and no JS then most modern browsers (apart from IE I think) would get the automatic x and clear function.
The type field is set to search, but on a mobile and on the pc the cross doesn’t appear, and this is why this was picked up in testing and I’m trying to fix it.
In ios the clear button was removed for some reason (Its there but hidden and does nothing if shown). On the PC the clear button is working fine in Chrome and Edge (not firefox) and is working on mac in safari and chrome.
Your example will therefore for most users be providing a double clear button and look very messy indeed. You should just use input type=“text” instead if you must have the js added so that you don’t get the double clear button.