Skip to content

Instantly share code, notes, and snippets.

@mazfreelance
Last active August 24, 2017 03:49
Show Gist options
  • Save mazfreelance/b992c27c661e4c0fa9cfef015c151b2b to your computer and use it in GitHub Desktop.
Save mazfreelance/b992c27c661e4c0fa9cfef015c151b2b to your computer and use it in GitHub Desktop.
JQUERY: hide and show input type="text"
<select name="oth" id="oth">
<option value="">Please Select</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="text" id="output" style="display: none"/>
$(document).ready(function(){
$("#oth").change(function() {
$(this).val() == "2" ? $('#output').show() : $('#output').hide();
});
});
//if want to play with php
<select name="oth" id="oth">
<option value="">Please Select</option>
<option value="1">1</option>
<?php
if($detail['1'] == '1'){ // $detail['1'] - retrieve data from dB
echo "<script>$(document).ready(function() { $('#output').show();});</script>";}
?>
<option value="2">2</option>
</select>
<input type="text" id="output" style="display: none"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment