Is there a way to have an HTML input element show based on the value of a select list/drop-down in HTML? So once one of the drop-down values is selected, then another input tag pops up. What I am looking for is to have another input tag pop up once one of the values are select, and based on the select value, it would be a certain type of input type tag.
I have been able to do it with having an input tag show and hide if a certain value is selected, so then I can use it with PHP in a form tag , but I can not seem to figure out how to get something like this to work. Here is the logic I am trying to accomplish:
if dropdown value is 'playswound'
then show input tag type=file
if dropdown value is 'saythis'
then show input tag type=text
if dropdown value is 'runcommand'
then show input tag type=text
if dropdown value is 'run program'
then show input tag type=file
Here is the HTML I have so far:
$default_select="Default Action";
echo "<select name='alarm_action' required>";
echo "<option value=$default_select>$default_select</option>";
echo "<option value='/usr/bin/mpg123'>Play Sound</option>";
echo "<option value=''>Say This</option>";
echo "<option value=''>Run Command</option>";
echo "<option value=''>Run Program</option>option>";
echo "</select>";
?>
Here is the JS code I got to work for one option for a dropdown:
$scriptTag = "
var speakerInput = $('#speaker');
speakerInput.on('change', function() {
speaker_other = $('#speaker_other');
if (speakerInput.val() == 'Other') {
speaker_other.show();
} else {
speaker_other.hide();
}
});";
HTML for JS above:
echo '<option value="Other">Other</option>';
echo '</select>';// Close your drop down box
echo '<input name="speaker_other" id="speaker_other" type="text" style="display: none" />';
echo '<script type="text/javascript">'.$scriptTag.'</script>';
so now I want to be able to have it where every option selected will have an input tag show, but based on the selected value, the input type would be different.