Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从条件jquery之后的选项获取值_Php_Jquery - Fatal编程技术网

Php 从条件jquery之后的选项获取值

Php 从条件jquery之后的选项获取值,php,jquery,Php,Jquery,我有一个选择选项,我需要选择一种产品,然后选择一种产品类型。 在这两个选择之后,我需要为它选择类别。 如果我选择某个产品和类型,它将自动为其选择一个类别,并将阻止类别选项 为此,我提出了以下条件: $( ".target" ).change(function() { var type = $('.target[data-prod=type]').val(); var product = $('.target[data-prod=product]').val(); if

我有一个选择选项,我需要选择一种产品,然后选择一种产品类型。 在这两个选择之后,我需要为它选择类别。 如果我选择某个产品和类型,它将自动为其选择一个类别,并将阻止类别选项

为此,我提出了以下条件:

 $( ".target" ).change(function() {
   var type  = $('.target[data-prod=type]').val();
   var product = $('.target[data-prod=product]').val();

     if (type == '1'  && product =='pillow') {
       $('#unhide').removeClass('hidden');
       $('.category').prop('disabled', true);

       $('div.cte select').val('color');   //this is wrong? not getting value of it after submit
     }else{
       $('#unhide').addClass('hidden');
       }

 });
顺便说一句,我的类别选择选项是动态的:

<div class="form-group cte">
<label>Categoria</label>
 <select  name="categoria" class="form-control  category">


 <?php  
   $sel_cat = "SELECT category_name FROM gallery_category ORDER BY category_name ASC";    
   $run_cat = mysqli_query($conn,$sel_cat);
   while($rows = mysqli_fetch_assoc($run_cat)){
    echo ' <option value="'.$rows['category_name'].'">'.ucfirst($rows['category_name']).'</option>';  
   }
 ?>
 </select>
</div>

范畴
我想选择此选项:

<option value="color'">Colors</option>
颜色
所以我可以得到它的价值后提交。 当我提交时,我的类别值为空,我该怎么办

obs: (我不太擅长jquery)


我知道这个php查询很容易受到攻击,只是通过这种方式简化了这里的操作。

硬编码您可以这样选择它:

$('[name=categoria]').val( 3 ); // select with index :3
$('#myFormId').submit(function() {
  $('.category').prop('disabled', false);
});
这不适用于您,因为您提到您的选项是动态的,所以我们需要从文本中选择它:

$('[name=categoria] option').filter(function() { 
    return ($(this).text() == 'Colors'); //To select on the string Colors
}).prop('selected', true);
或动态使用该值:

$('[name=categoria] option').filter(function() { 
    return ($(this).val() == 'color'); //To select on the value color
}).prop('selected', true);

将禁用的属性添加到表单输入会使它们在提交的数据中不可用。您正在禁用此行中的选择:

$('.category').prop('disabled', true);
这就是为什么您得到的是空值。尝试在表单提交时启用它以允许数据访问,如下所示:

$('[name=categoria]').val( 3 ); // select with index :3
$('#myFormId').submit(function() {
  $('.category').prop('disabled', false);
});

使用
.val()
获取所选值,从现在开始,您将其设置为.val('value=“color”)<代码>$('div.cte select').val()您正在使用
$('.category').prop('disabled',true)禁用类别选择在表单提交时使其值为空。检查您是否在没有在选择上添加disabled属性的情况下获得该值