0

i have a html select with options in my views .onchangei want to invoke action of my controller. Important: i am not going to do this through Ajax because onchange my whole module is changing so i want to refresh a page each time onchange.

                   <select id="p_s">
                   <?php  foreach($this->active_services as $row){ ?>
                    <option value="<?php echo $row['ph_id'];?>"><?php echo $row['ph_name'];?></option>
                      <?php }?>
                    </select> 

the action i am calling also included the below code so i am not going to do it through ajax.

            if(!$this->_request->isXmlHttpRequest()){
             //The request was not  made with JS XmlHttpRequest
              $user = new Zend_Session_Namespace('user');
              $user_id =$user->user_id;  
              $object   = new Services();
              $active_services     = $object->Get_Current_User_Active_Services($user_id);
              $this->view->assign('active_services',$active_services );
            }

the action i am calling is invoking through both ajax and normal this time i am calling it normal. Any idea would be helpful.

hakre
  • 193,403
  • 52
  • 435
  • 836
Edward Maya
  • 429
  • 2
  • 10
  • 25

1 Answers1

2
<select id="p_s">
    <?php foreach($this->active_services as $row) : ?>
        <option value="<?php echo $this->url(array(
                "module" => "yourModule",
                "controller" => "yourController",
                "action" => "yourAction",
                "p_s" => $row['ph_id']
            ),
            $yourRouteName=null,
            $reset=true); 
            ?>
         ">
            <?php echo $row['ph_name'];?>
        </option>
    <?php endforeach ?>
</select>

Then

$("#p_s").change(function() {
    window.location.href = $(this).val();
});
bububaba
  • 2,840
  • 6
  • 25
  • 29
  • sir i want to send $row['ph_id'] as a parameter to my action ??does the code you provided doing so ?? – Edward Maya Mar 29 '12 at 11:29
  • yourRouteName ??? example please.sir plz dont mind my awkward questions i am new to ZF – Edward Maya Mar 29 '12 at 11:30
  • 1
    `$yourRouteName` is optional if you want to use a custom route that you have defined. If you don't, set it to `null`. `$row['ph_id']` will be set as `p_s` parameter (see `"p_s" => $row['ph_id']`). – bububaba Mar 29 '12 at 11:41