简体   繁体   English

如果产品已经存在,则禁用按钮

[英]disabling a button if the product already exist

This is the JavaScript Function that Jump to the relevant page 这是跳转到相关页面的JavaScript函数

    function bun(){
    //var quantity=parseInt(fid);   

        window.location = 'ubun.php'    

    }

    function pat(){
    //var quantity=parseInt(fid);   

        window.location = 'upatties.php'    

    }
    function pats(){
    //var quantity=parseInt(fid);   

        window.location = 'utoppings.php'   

    }
    function sau(){
    //var quantity=parseInt(fid);   

        window.location = 'usauces.php' 

    }

</script>

This is the if else function code that are problematic 这是有问题的if else函数代码

<input type="button" value="Bun Selection" 
      <?php 
      if($fid==4 || $fid==8 || $fid==11 ||$fid==21 ||$fid==5 ||$fid==6||$fid==7||$fid==9||$fid==10||$fid==41||$fid==40||$fid==12||$fid==13||$fid==14
                ||$fid==15||$fid==16||$fid==17||$fid==18||$fid==19||$fid==20||$fid==22
                ||$fid==23||$fid==24||$fid==25||$fid==26||$fid==27||$fid==28||$fid==29
                ||$fid==30) 
      {
         echo ' disabled=disabled ';
      }
      else
      {
            echo ' onclick=bun() ';
      }

    ?>
     />

     <input type="button" value="Patties Selection" 
      <?php 


      if($fid==8 || $fid==11 ||$fid==21 
                ||$fid==9||$fid==10||$fid==41||$fid==40||$fid==12||$fid==13||$fid==14
                ||$fid==15||$fid==16||$fid==17||$fid==18||$fid==19||$fid==20||$fid==22
                ||$fid==23||$fid==24||$fid==25||$fid==26||$fid==27||$fid==28||$fid==29
                ||$fid==30) 
      {
         echo ' disabled=disabled ';
      }
      else
      {
          echo ' onclick=pat() '; 
      }

    ?>
    />

     <input type="button" value="Toppings Selection" 
      <?php if($fid==11 ||$fid==21
                ||$fid==40||$fid==12||$fid==13||$fid==14
                ||$fid==15||$fid==16||$fid==17||$fid==18||$fid==19||$fid==20||$fid==22
                ||$fid==23||$fid==24||$fid==25||$fid==26||$fid==27||$fid==28||$fid==29
                ||$fid==30) 
      {
         echo ' disabled=disabled ';
      }
      else
      {
          echo 'onclick=pats()'; 
      }
    ?>
    />


     <input type="button" value="Sauces Selection" 
      <?php if($fid==21 || $fid==22
                ||$fid==23||$fid==24||$fid==25||$fid==26||$fid==27||$fid==28||$fid==29
                ||$fid==30||$fid==40) 
      {
         echo ' disabled=disabled ';
      }
      else
      {
          echo ' onclick=sau() '; 
      }
    ?>
/>

The above code run smoothly when i first go to the shopping cart bun, then patties then toppings and finally sauces. 当我第一次去购物车面包时,上面的代码运行平稳,然后是肉饼,然后是浇头,最后是调味料。 the button will disable one at a time for example if i pick bun then the bun selection will be disable, it is the same with patties, toppings and sauces, the button will disable after the selected product are chosen inorder. 该按钮将一次禁用一个,例如,如果我选择面包,则面包选择将被禁用,与小馅饼,浇头和调味料相同,在按顺序选择所选产品后,该按钮将被禁用。

If it is in random then my main problem is that when i pick sauce first then the other three button (bun, patties and toppings) will also disappear. 如果是随机的,那么我的主要问题是,当我首先选择酱汁时,其他三个按钮(小圆面包,肉饼和浇头)也将消失。 It is the same with if i choose toppings first the other two button (bun and patties) will disappear, but the sauce button can be click. 如果我先选择浇头,其他两个按钮(小圆面包和肉饼)将消失,但是可以单击酱汁按钮。

I was trying to pick the product at random choices.Are there any solution to my problem? 我试图随机选择产品,我的问题有解决方案吗?

fid is the id for product id...... for bun id (4,5,6,7) for patties id (8,9,10,41) for toppings id (11,12,13,14,15,16,17,18,19,20) for sauces id (20,21,22,23,24,25,26,27,28,29,30,40) fid是产品ID的ID ......对于面包ID(4,5,6,7)的面包ID(8,9,10,41)对于浇头ID(11,12,13,14,15) ,16,17,18,19,20)用于调料ID(20,21,22,23,24,25,26,27,28,29,30,40)

Try to use in_array function in php. 尝试在php中使用in_array函数。 it make your code easier to read and clean 它使您的代码更易于阅读和清理

<?php
        $fid =7; // this is only to show
        $ids = array(1,2,3,4,5,6,8,); // this is the array item to be compare

        if (in_array($fid, $ids)) // check if $fid is in list ($ids)
        {
            echo ' disabled=disabled '; // this will output if $fid is in the array list
        }else{
            echo ' onclick=bun() '; // this will output if $fid is not in the array list
        }
?>

this will ouput "onclick=bun()" because 7 is not in the list. 这将输出“ onclick = bun()”,因为列表中没有7。 Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM