How to make a search function with dropdown? - javascript

I have a website with a lot of products I've made in Wordpress. To make it easy for my visitors, I would like to make a search function with dropdowns.
My idea is, that my visitors have to select some categories in some dropdowns, and eventually press a search button to then display products that matching, what the visitors had chosen.
These types of dropdowns I think are like thise: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select

For that you need to create a custom dropdown and not select list. ALternatively you can use datalist
<form action="/action_page.php" method="get">
<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>

Related

populate selected options dynamically in multiselect dropdown using javascript

I need a multi-select drop-down list with a checkbox which will allow a user to select multiple options without pressing command/ctrl buttons please help on this
<select id='testSelect2' name="test" multiple>
<option value='1'> sunday</option >
<option value='2'> monday</option>
<option value='3'> tuesday</option>
<option value='4'> wensday</option>
<option value='5'> thrusday</option>
<option value='6'>friday </option>
<option value='7'>saturday </option>
</select>
enter image description here
If you are using bootstrap, you can use this plug in http://davidstutz.de/bootstrap-multiselect/
If you want to do this with vanilla javascript, you may try to handle click event on options and achieve this behaviour manually.

dropdown options change based on another dropdowns choices

I have a form that has several dropdowns. I need to make the second dependent on the value of the first. I have a Codepen that shows four dropdowns. The first does not change but the selects 2, 3, and 4 show the intended options I want.
Here is a listing of what option of dropdown 1 leads to the second.
new -> input-2
client -> input-3
admin -> input-4
I am doing this in OpenCart in a MVC so I am a little confused if this all is done in the view file or do I need to have some of this done in the controller, and if so how? I do believe JavaScript would be able to help here but not really sure how to implement that. My code pen is:
https://codepen.io/anon_guy/pen/pdbYad
<form action="/action_page.php">
<select name="Input-1">
<option value="*"></option>
<option value="new">new</option>
<option value="client">client</option>
<option value="admin">admin</option>
</select>
<select name="Input-2">
<option value="sign-up">Sign Up</option>
</select>
<select name="Input-3">
<option value="upgrade">upgrade</option>
<option value="stats">stats</option>
</select>
<select name="Input-4">
<option value="view-accounts">view all</option>
<option value="add">add</option>
<option value="remove">remove</option>
</select>
<input type="submit">
</form>

A drop down select that's actually a text input box, like on Google Calendar?

I noticed Google calendar uses this instead of <select>
<input class="text dr-time" id=":3r-st" size="7" title="From time" tabindex="0" dir="ltr" />
It let's the user type the time instead of selecting an option from the drop down list. Is there a plugin or nice widget someone wrote that does the same thing?
You might want to have a look at one of these JQuery plugins:
http://ivaynberg.github.io/select2/
http://brianreavis.github.io/selectize.js/
http://harvesthq.github.io/chosen/
A more lightweight approach might be, assuming you only have text and not dates, using the data-list attribute:
<div>Choose a browser from this list:</div>
<input list="browsers" />
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
</datalist>
I copied the above code from here: https://developer.mozilla.org/en/docs/Web/HTML/Element/datalist
Maybe Chosen is something for you. It's a JavaScript SELECT replacement, which adds multiple new opportunities:
http://harvesthq.github.io/chosen/

Is it possible to change the input[type=text] history?

When you click on an input[type=text] field with autocomplete=on the browser shows hints of the previous inputs. I want to change the values of those hints to my own recommendation list. I could build that feature from scratch but I'm wondering if I could change the hint values to save time. Is it possible? If so, how?
<input type="text" list="browserList" name="browser">
<datalist id="browserList">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Demo

Dropdown with autocomplete + static values

I want to create a dropdown when you click on an icon where you can search through data. I will clarify this with an image:
You can type your quiz name on the .... rule.
Then in the second part of the dropdwon you will see the quizzes from the database depending on the search terms.
In the third part of the dropdown I want to show the last 5 surveys (this has to be static, not chaning when the search terms change).
In the fourth part of the dropdown I also want to show static values.
Is this possible to do with select2.js ?
Or can someone help me start with this? I don't really have a clue on how to begin with this. I know how you can show data according to the search terms. But it's the third and fourth part of the dropdown that I don't really know how to show also under it ...
you can use any dropdown api but if you want to autocomplete with static value you should use html5 form element "<datalist >"
here is example
<form action="demo_form.asp" method="get">
<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input type="submit">
</form>

Categories

Resources