php - Dynamically validate user selection using ajax/Javascript -


see below simple html form. want user pick product dropdown list.after this, proceed pick quantity next dropdown list , add cart.

here question: @ point of selecting quantity, want system dynamically go database(php/mysql), compare database qty selected value. if greater stock value(total value in db), should pop message alert box , disable submit buttom, otherwise should add cart , enable submit button.

i have looked @ many ajax examples , help, hasn't been able it. appreciate sample/modification if necessary.

<p>product name:<select name="prod_name" size="1"> <option value="select">select</option> <?php while ($line = mysqli_fetch_array($query, mysql_assoc)) {   ?> <option value="<?php echo $line['prod_name'];?>"><?php echo $line['prod_name'];?> </option>   <?php } ?>   </select></p> <p>quantity:<input  type="number" name="qty"  size="30"  required="required"/></p> <input name="submit" type="submit" value="add cart" /> | <input name="reset" type="reset" value="cancel" /> 

so, use jquery. first thing fire off code when quantity changes

<script> $( "input[name='qty']" ).change(function() {     alert( "handler .change() called selected quantity " + this.value); }); </script> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -