不允许从db中选择相同的值,但在javascript中选择

时间:2016-10-09 16:11:21

标签: javascript php mysql

我试图从javascript中的db中选择一个值。如果select在javascript中,为什么这不起作用。

$(document).ready(function() {
var max_fields      = <?php foreach ($results2 as $rss) { ?><?php echo $rss["qty"]; ?><?php } ?>; //maximum input boxes allowed
var wrapper         = $(".input_fields_wrap"); //Fields wrapper
var add_button      = $(".add_field_button"); //Add button ID

var x = 0; //initlal text box count
$(add_button).click(function(e){ //on add input button click
    e.preventDefault();
    if(x < max_fields){ //max input box allowed
        x++; //text box increment
        $(wrapper).append('<div><br><tr><td><label for="kind">Part Number / part Name</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="qty">Quatity (Pcs)</label><br><select name="kind[]" class="select1" required><option value="">Please Select</option><?php foreach ($results1 as $rs) { ?><option value="<?php echo $rs["part_number"]; ?>/<?php echo $rs["part_name"]; ?>"><?php echo $rs["part_number"]; ?>  --  <?php echo $rs["part_name"]; ?></option><?php } ?></select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="qty[]" value="" autocomplete="off" onkeypress="return isNumberKey(event)" required/></td></tr><tr></tr><a href="#" class="remove_field">&nbsp;Hapus</a></div>'); //add input box
    }
});

$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
    e.preventDefault(); $(this).parent('div').remove(); x--;
}) });

这是隐藏的,如果在选择下拉列表之前

  $(document).ready(function(){   
$("select").change(function() {   
$('select[name="kind[]"]').not(this).find("option[value="+ $(this).val() + "]").attr('hidden', true); }); });

我从这里学到了 Prevent selecting same value in three different dropdowns

0 个答案:

没有答案