Select and open a SELECT element from another event

Possible duplicate:
Is it possible to open a dropdown with jQuery

Want to open the drop-down list by clicking on the text box - is this possible?

I'm currently trying to use jquery-mobile and want to open SELECT-BOX on an iPhone / Android device.

Here is my code

JS:

function showScoopCategory() { console.log('showScoopCategory'); $('#scoopCategory').click(); // Not opening the dropdown } 

HTML:

 <select id="scoopCategory" name="grievence"> <option value="1">Option One</option> <option value="2">Option Two</option> <option value="3">Option Three</option> </select> ... <textarea id="scoopCategoryText" placeholder="Select & Open Dropdown" onClick="showScoopCategory();"></textarea> 
+4
source share
2 answers

adjusting the focus () on the SELECT element works on the iPhone.

But first, the keyboard for the text field opens, then it deletes it and displays a selection window.

So, I plan to delete the text box and create a div there as textarea. Thus, onClick it will not open the keyboard, and it can directly open Select-Box.

 function showScoopCategory() { console.log('showScoopCategory'); $('#scoopCategory').focus(); // opening keypad, then removes it & opens Select box } 
+1
source

I don’t think you can open it like a normal click. However, you can increase its size.

 $('#scoopCategoryText').on('focus', function() { var $sCategory = $('#scoopCategory'), numCategories = $sCategory.find('option').length; console.log('showScoopCategory'); $sCategory.attr('size', numCategories); }).on('blur', function() { $('#scoopCategory').attr('size', 1); }); 

You can also make a layout with a drop-down list with HTML and CSS, but getting it right away won't be quick and easy.

+2
source

Source: https://habr.com/ru/post/1400104/


All Articles