0

I have dropdown-menu-1 with medicine names from my database. what I need to happen is when I select a specific medicine from dropdown-menu-1, Dropdown-menu-2 automatically shows the quantity of that medicine from the database.

I think my problem is how to do the query inside the javascript.

Database:

medicine A with a quantity of 5

medicine B with a quantity of 7

medicine C with a quantity of 10

if you click medicine a, the option in dropdown-menu-2 should be from 1 to 5, if medicine b, the option in dropdown-menu-2 should be from 1 to 7 and medicine c should be from 1 to 10.

--> Dropdown-menu-1

--> Dropdown-menu-1 | Dropdown-menu-2

Here's my code:

<select id="one">
<?php 

while ($print = mysql_fetch_array($query3)){

  echo "<option value\"".$print['generic_name']." ".$print['brand_name']."\">".$print['generic_name']." ".$print['brand_name']."</option>"; }

?>
</select>

<select id="two"></select>

<script type="text/javascript">
$(function () {
    $("#one").change(function (e) {
        $("#two").empty();

<?php $query4 = mysql_query("SELECT * FROM medicine, status WHERE     medicine.med_id=status.med_id AND medicine.generic_name=")?>

        var options = 
        $("#one option").filter(function(e){
            return $(this).attr("value") > $("#one option:selected").val();
        }).clone();

        $("#two").append(options);
    });
});
</script>

-HTML RENDER-

I was ready to post a picture of the html render in my post, I didn't know I needed 10 rep points to add an image to my post. I posted it on photobucket instead http://s1132.photobucket.com/user/klleww/media/post.png.html

  • If you want to do this with JavaScript, please show the rendered HTML (as seen by the browser), *not* the (server-side) [tag:php] script that generates it (which is irrelevant to JavaScript). – David Thomas Oct 07 '14 at 15:22
  • You have two ways of approaching this, load all the second options and filter them, or make an ajax to get the second options. Of course I would suggest the first one, as the quantity is a small data. – Pablo Matias Gomez Oct 07 '14 at 15:22
  • possible duplicate of [How to populate a cascading Dropdown with JQuery](http://stackoverflow.com/questions/18351921/how-to-populate-a-cascading-dropdown-with-jquery) – Jay Blanchard Oct 07 '14 at 15:27
  • @DavidThomas ..html render posted – user3632739 Oct 07 '14 at 15:48

0 Answers0