I have multiple PHP files that interact with eachother, and I have a function called display_lang_offer() on the output.php file that gets called in the lang_offer.php file which is shown below:
function display_lang_offer(){
//languages offered
?>
<form>
<select name="languages">
<option></option>
<option value"html">HTML</option>
<option value"css">CSS</option>
<option value"js">JavaScript</option>
<option value"csharp">C#</option>
<option value"php">PHP</option>
<option value"java">Java</option>
<option value"phython">Phython</option>
</select>
<br><br>
</form>
<div class="section" id="html">html content here</div>
<div class="section" id="css">CSS content here</div>
<div class="section" id="js">js content here</div>
<div class="section" id="csharp">csharp content here</div>
<div class="section" id="php">php content here</div>
<div class="section" id="java">java content here</div>
<div class="section" id="phython">phython content here</div>
And the Javascript is:
var id;
$("#languages").on("change",function(){
id=$(this).val();
$(".section").hide();
$("#"+id).stop().show();
})
And the CSS is:
.section{display:none}
How do I get it, that when I select the HTML option, the HTML content gets displayed? Then if I choose the Java option, the HTML option disappears and the Java one appears.
Edit
The entire function now is:
function display_lang_offer(){
//languages offered
?>
<script>
var id;
$("#languages").on("change",function(){
id=$(this).val();
$(".section").hide();
$("#"+id).stop().show();
})
</script>
<style>
.section{display:none;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<select name="languages"id="languages">
<option></option>
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
<option value="csharp">C#</option>
<option value="php">PHP</option>
<option value="java">Java</option>
<option value="python">Python</option>
</select>
<br><br>
</form>
<div class="section" id="html">html content here</div>
<div class="section" id="css">CSS content here</div>
<div class="section" id="js">js content here</div>
<div class="section" id="csharp">csharp content here</div>
<div class="section" id="php">php content here</div>
<div class="section" id="java">java content here</div>
<div class="section" id="python">python content here</div>
I've tried both answers but neither seem to work
$("#languages")--- I don't see that ID on your select element<select id="languages">or check the answer from @JorgeObregonname!=id.$('#foo')is NOT going to find<select name="foo">