English 中文(简体)
CakePHP下降,选定物品改用于对项目进行观察
原标题:CakePHP drop down, selected item redirect to view for item

我要谈谈所选毒品的看法。 因此,他们点击了“Acetamenophen”这一毒品,我希望把他们寄给该毒品的观点。 如果没有增加一个提交国,我怎么做?

法典 我降幅:

<?php
echo $form->input( Drug.generic , array( type  =>  select ,  label  =>  Quick Select: ,
   empty  =>  Select ,  options  => $alldrugs)
);
?>

指数控制者行动(下降的口号在上)

  function index() {
    $this->set( drugs , $this->Drug->find( all ));
    $this->set( alldrugs , $this->Drug->find( list , array( fields  => array( id , generic ),  order  =>  Drug.generic ,  recursive  => -1,)));
  }
最佳回答

您可在default.ctp的js变量中储存根l。 如下:

将这一代码置于违约之下:ctp<head></head>节。

<script>
  var _ROOT = "<?php echo $this->Html->url( / , true); ?>";
</script>

在<代码><head> tag在</head> end:

<?php echo $this->Html->script(array( jquery ,  drug_list )); ?>

Then use the _ROOT like following:

window.location = _ROOT +  drugs/view/  + val;

Place jquery Library and make a YOURNAME.js file in app/webroot/js rafter and place following Code with YNAME.js.

页: 1 页: 1

$(function() {
   $( #ID_OF_YOUR_SELECT_BOX ).change(function() {   // replace the ID_OF_YOUR_SELECT_BOX with the id to your select box given by Cake
       var val = $(this).val();  // val is the drug id
       window.location = _ROOT +  drugs/view/  + val;
    });
});
问题回答

i d put the select inside a form without the submit button, and add a onclick to the select (you don t actually need a whole framework for it):

<?php
echo $form->input( Drug.generic , array( type  =>  select ,  label  =>  Quick Select: ,
   empty  =>  Select ,  options  => $alldrugs,  onchange => this.form.submit(); )
);
?>

当然,在控制器中,必须检查<代码>this->data,并根据选择或如果你有意将用户重新定位,将用户转至正确的网页,只是根据发现情况改变条件。

Hope this helps,

有了四舍五入和购买力平价,你可以直接转向你想要采取的行动:

<?php
echo $form->input( Drug.generic , array( type  =>  select ,  label  =>  Quick Select: ,
   empty  =>  Select ,  options  => $alldrugs,  id  =>  drug_select )
);
?>

$(document).ready(function(){

    $("#drug_select").change(function(){
        var drug_id = $(this).val();
        if(drug_id.length > 0)
        {
            window.location = "<?php echo Router::url(array( controller  =>  drugs ,  action  =>  view ), true) ?>/" + drug_id;
        }
    });

});




相关问题
PHP Combo Box AJAX Refresh

I have a PHP page that currently has 4 years of team positions in columns on the page. The client wants to select the players in positions and have first, second and thrid choices. Currently the page ...

jquery + ajax + json + fill dropdown list not working

I m pretty sure i am almost there....but i cannot figure out how to iterate through json objects and fill a dropdown list. Here is the js code: My JSON data returned:{"name":"County1","name":"County1"...

Gridviews and DropdownLists

Is it possible to change the data source of a dropdown list in a gridview from another dropdown list selected index changed method in the same gridview? for example I have a dropdown that needs to ...

Adding a new value to the drop down list box

I have a drop down list box which has one of the values to be others. I want to move these value to the last. Please help me with this. The code i am using is as follows ddlAssetsCountryOthersone....

Show hide div using codebehind

I have a DropDownList for which I am trying to show a div OnSelectedIndexChanged but it says OBJECT REQUIRED. I am binding the DataList in that div: aspx: <asp:DropDownList runat="server" ID="...

Why might dropdownlist.SelectedIndex = value fail?

I have a dropdown list that I am binding to a datatable. Here is the code I am using to do it: ddlBuildAddr.DataSource = buildings ddlBuildAddr.DataTextField = "buildingName" ddlBuildAddr....

热门标签