dongzhao3040 2015-09-16 07:08
浏览 7
已采纳

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

This is the JavaScript Function that Jump to the relevant page

    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

<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)

  • 写回答

1条回答 默认 最新

  • dongyu3659 2015-09-16 08:11
    关注

    Try to use in_array function in php. 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. Hope this will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上