Ghokun
Ghokun

Reputation: 3475

Searchbutton click event

When I press enter it works great. However I also want to perform search by clicking the searchbutton in the text box. I added oncommand attribute, it performed the search however after search ended, searchbutton changed into a cross. I clicked the cross it performed the search again. I checked the documentation however could not find any information about how to associate my searchbutton click with search event.

    <textbox id="txt1" type="search" searchbutton="true" editable="true"
    onkeypress="keyHandler(event);" />

Upvotes: 1

Views: 299

Answers (2)

linguini
linguini

Reputation: 1939

This solution is mayn't corresponding to your problem but this will give an idea to finsh your task.

XUL Textbox:

<textbox id="textbox" type="search" oncommand="SearchKeyword(this)"/>

Js:

function SearchKeyword(oElem) // Function for search for the characters
        {
         var filter = document.getElementById("textbox");
         filter.setAttribute("value", oElem.value);
         document.getElementById("myTodoListTree").builder.rebuild();
      }

Upvotes: 1

Wladimir Palant
Wladimir Palant

Reputation: 57701

First a side-note: Do not process clicks or key presses directly, always use the command event - this makes sure the behavior of the element is consistent with what the user expects.

<textbox type="search"> assumes that performing the same search twice makes no sense. So after performing the search the search button changes into a cross, clicking that cross clears the search text (and triggers a new command event of course). If instead of clicking the cross you change the search text you will get the usual search button again. So your command handler should look at the search text: show default results if the text is empty (search text cleared either manually or by pressing the cross) and perform a new search if the text is non-empty.

Upvotes: 1

Related Questions