dpr26232 2013-03-18 15:23
浏览 20
已采纳

CodeIgniter额外选项值

I have been pulling my hair out for god knows how long trying to work this out.

Currently I have a select list (form_dropdown) like this.

<select name="starters">
<option value="">Please Select</option>
<option value="0" >Brochettes</option>
<option value="1" >Grilled mackerel</option>
<option value="2" >Risotto cake</option>
<option value="3" >Calamari rings</option>
<option value="4">Parma ham parmesan</option>
</select> 

What I need to do Is pass into this form_dropdown is a Price Value, so I can have a dynamic price calculator on the website.

<select name="starters">
<option value="" price="100">Please Select</option>
<option value="0" price="22">Brochettes</option>
<option value="1" price="342">Grilled mackerel</option>
<option value="2" price="42">Risotto cake</option>
<option value="3" price="52">Calamari rings</option>
<option value="4" price="22">Parma ham parmesan</option>
</select> 

Is there any way I can do this? Im really stuck for dead lines and I thought this would be possible in code igniter.

My code so far, as you can see I have a price, but I need to pass it into the option.

            echo form_label("APPETISERS", "appetisers");
            $array = array();
            foreach($appertisers as $row ){
                 $array[] = $row->product;
                 $price[] = $row->price;
            }
            $array = array_merge(array('' => 'Please Select'), $array);
            echo form_dropdown('appetisers',  $array);
  • 写回答

2条回答 默认 最新

  • duanmo7075 2013-03-18 16:11
    关注

    Well I don't know how to do that with the codeingiter form_label, mostly because I don't use the form_helper to create inputs.

    Usually I do this way:

    <select name="starters">
      <option value="">Please Select</option>
      <?php foreach($appertisers as $row ):?>
      <option value="<?=$row->id?>" data-price="<?=$row->price?>"><?=$row->product?></option>
      <?php endforeach;?>
    </select>
    

    I've named your price attribute to data-price, this way you can use the data function like this:

    var price_value = $('select[name="starters"] option:selected').data('price');
    

    You can read more about the data attribute here http://api.jquery.com/data/ and here http://html5doctor.com/html5-custom-data-attributes/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: