3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if (isset($_POST['submit'])) echo $_POST['item'].$_POST['cat']; ?> <form method="POST"> <select id="cat" name="cat"> <option val="car">car</option> <option val="phone">phone</option> </select> <select id="item" name="item"> </select> <input type="submit" name="submit" /> </form> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> cars=new Array("Mercedes","Volvo","BMW","porche"); phones=new Array('Samsung','Nokia','Iphone'); populateSelect(); $(function() { $('#cat').change(function(){ populateSelect(); }); }); function populateSelect(){ cat=$('#cat').val(); $('#item').html(''); if(cat=='car'){ cars.forEach(function(t) { $('#item').append("<option value='"+t+"'>"+t+"</option>"); }); } if(cat=='phone'){ phones.forEach(function(t) { $('#item').append("<option value='"+t+"'>"+t+"</option>"); }); } } </script>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<form method="POST"> <select id="cat" name="cat"> <option val="car">car</option> <option val="phone">phone</option> </select> <select id="item" name="item"> </select> <input type="submit" name="submit" /> </form> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> cars=new Array("Mercedes","Volvo","BMW","porche"); phones=new Array('Samsung','Nokia','Iphone'); populateSelect(); $(function() { $('#cat').change(function(){ populateSelect(); }); }); function populateSelect(){ cat=$('#cat').val(); $('#item').html(''); if(cat=='car'){ cars.forEach(function(t) { $('#item').append("<option value='"+t+"'>"+t+"</option>"); }); } if(cat=='phone'){ phones.forEach(function(t) { $('#item').append("<option value='"+t+"'>"+t+"</option>"); }); } } </script>