I want to use a select
element for mobile viewing of my website. Following is the select
options.
HTML:
<select name="select-choice-8" id="select-choice-nc">
<optgroup label="News">
<option value="feature">Fea</option>
<option value="current">Current</option>
<option value="research">Research</option>
</optgroup>
<optgroup label="Archive">
<option value="archive">Archive</option>
</optgroup>
<optgroup label="Video">
<option value="">Video</option>
</optgroup>
<optgroup label="Submit">
<option value="">Story</option>
<option value="">Event</option>
</optgroup>
</select>
I want use JavaScript / jQuery to do some AJAX calls based on the what the user selects in order to avoid reloading the whole page (e.g. filling a container with the returned AJAX content).
I need some ideas or examples to solve this problem.
Thanks in advance.
I'm not that familiar with jQuery but you'll be able to find the right syntaxis. The idea is just to get the appropriate HTML based on your selected option. That is, its corresponding value.
Consider testHTML:
And JavaScript:
Or maybe even:
And
Try this: http://shaquin.tk/experiments/select-ajax2.html.
HTML:
JS:
PHP:
CSS (optional):
In the PHP, you would probably want to fetch the text from a database: PHP - MySQLi.