I have a regular select list and I would like to:
- Expand it on button, that is working and done
- Keep hidden select list until the button is clicked.
- I would like list options to be onclick event.
Any ideas and suggestions please?
showDropdown = function (element) {
var event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
element.dispatchEvent(event);
};
window.runThis = function () {
var dropdown = document.getElementById('dropdown');
showDropdown(dropdown);
};
<select id="dropdown">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br>
<button id="fire" type="button" onclick="runThis()">Show dropdown items</button>
Alternatively what is the best way of doing Select list that respond as spinner on adndroi and ios devices?
UPDATE
Let me update Question now as part of this is now working:
function get_tables_restaurant(){
if($result2 = $this->db->query('SELECT * FROM fandb_tables ORDER BY title ASC')){
$return .= '<div class="lineheight"><button id="fire" type="button" class="add_table">+</button></div>
<select id="dropdown">';
while($r2 = $result2->fetch_object()){
$return .= '<option value="'.htmlspecialchars($r2->title).'">'.htmlspecialchars($r2->title).'</option>';
}
$return .= '</select>';
$return .= '<div id="test2" style="display: none;">
<h4>Table '.htmlspecialchars($r2->title).'</h4>
<form method="post" action="">
<input type="hidden" name="area" size="50" value="'.htmlspecialchars($r2->area).'"/>
<input type="hidden" name="tableno" size="50" value="'.htmlspecialchars($r2->title).'"/>
<input type="hidden" name="title" size="50" value="1"/>
<input type="submit" value="STARTER" class="starter"/>
</form>
<form method="post" action="">
<input type="hidden" name="area" size="50" value="'.htmlspecialchars($r2->area).'"/>
<input type="hidden" name="tableno" size="50" value="'.htmlspecialchars($r2->title).'"/>
<input type="hidden" name="title" size="50" value="2"/>
<input type="submit" value="MAIN COURSE" class="maincourse"/>
</form>
<form method="post" action="">
<input type="hidden" name="area" size="50" value="'.htmlspecialchars($r2->area).'"/>
<input type="hidden" name="tableno" size="50" value="'.htmlspecialchars($r2->title).'"/>
<input type="hidden" name="title" size="50" value="3"/>
<input type="submit" value="DESSERT" class="dessert"/>
</form>
<button onclick="$(\'#test2\').popup(\'hide\');" id="dismiss">DISMISS</button>
</div>';
}
So now for each option I need to show popup which is test2
id div with individual values as per above example.
I do get that this has to be inside the loop while
however it than doesnt work at all as soon as I will place this <div id="test2>...</div>
inside the loop.
Please can I ask you guys for advise?
SORTED!
:) as you said bit of reading and done:)
$( "#dropdown" ).change(function() {
var element = document.getElementById('dropdown');
$('#test2'+element.value).popup('show');
Thank you for everyones help:)