forms - PHP Select Option from other select value -
this question has answer here:
if select 'man' in first select second select option show man's product database. if select 'woman' in first select second select option show woman's product database. how can set system?
<form method="post" action="" > <label>category</label></br> <select name="cat"> <option value="man">man</option> <option value="woman">woman</option> </select></br></br> <label>product</label></br> <select name="product"> <option value="">select product</option> </select></br></br> <input type="submit" name="submit" value="submit"/> </form>
$(document).ready(function(){ $("select.cat").change(function(){ var selectcat = $(".cat option:selected").val(); //sample data - code starts here var data = '[{"id":1,"name":"product 1"},{"id":2,"name":"product 2"}, {"id":3,"name":"product 3"}]'; data = jquery.parsejson( data ); //sample data ends here $('#response').html(''); $('#response').append(' <label>product:</label><select class="product" id="product"> </select> '); $('#response select').append($("<option />").val('').text('select')); $.each(data,function(index, value){ $('#response select').append($("<option />").val(value.id).text(value.name)); }); //add above code ajax success - code ends here.. //return false; $.ajax({ type: "get", url: "process-ajax.php", data: { cat : selectcat } }).done(function(data) { }); }); });
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <form> <table> <tr> <td> <label>category:</label> <select class="cat"> <option>select</option> <option value="1">man</option> <option value="2">woman</option> </select> </td> <td id="response"> </td> </tr> </table> </form>
Comments
Post a Comment