Closed Thread
Results 1 to 4 of 4

Thread: codeigniter with jquery

  1. #1
    yonghan is offline Learning Programmer
    Join Date
    May 2008
    Posts
    99
    Rep Power
    0

    codeigniter with jquery

    Hi all,i got codes in CI views like this

    admin/product_home.php
    Code:
    <h1><?php echo $title;?></h1>
    <p><?php echo anchor("admin/produk/create""Create new product");?> | <?php echo anchor("admin/produk/export","Export");?></p> 

    <?php
    echo form_open_multipart("admin/products/import");
    $data = array('name' => 'csvfile''size'=>15);
    echo 
    form_upload($data);
    echo 
    form_hidden('csvinit',true);
    echo 
    form_submit('submit','IMPORT');
    echo 
    form_close();
    ?>

    <?php
    if ($this->session->flashdata('message')){
        echo 
    "<div class='message'>".$this->session->flashdata('message')."</div>";
    }

    if (
    count($products)){
        echo 
    form_open("admin/products/batchmode");
        echo 
    "<p>Category: "form_dropdown('category_id',$categories);
        echo 
    "&nbsp;";
        echo 
    "</p>";
        echo 
    "<table border='1' cellspacing='0' cellpadding='3' width='500'>\n";
        echo 
    "<tr valign='top'>\n";
        echo 
    "<th>&nbsp;</th><th>ID</th>\n<th>Nama</th><th>Status</th><th>Actions</th>\n";
        echo 
    "</tr>\n";
        foreach (
    $products as $key => $list){
            echo 
    "<tr valign='top'>\n";
            echo 
    "<td align='center'>".form_checkbox('p_id[]',$list['id'],FALSE)."</td>";
            echo 
    "<td>".$list['id']."</td>\n";
            echo 
    "<td>".$list['nama']."</td>\n";
            echo 
    "<td>".$list['status']."</td>\n";
            echo 
    "<td align='center'>".$list['status']."</td>\n";
            echo 
    "<td align='center'>";
            
    //echo anchor('admin/products/edit/'.$list['id'],'edit');
            
    echo anchor("admin/produk/edit/".$list['id'],img(base_url().'/images/edit.jpg'));
               echo 
    " | ";
            
    //echo anchor('admin/products/delete/'.$list['id'],'delete');
            
    echo anchor("admin/produk/edit/".$list['id'],img(base_url().'/images/edit.jpg'));
               
            echo 
    "</td>\n";
            echo 
    "</tr>\n";
        }
        echo 
    "</table>";
        echo 
    form_close();
    }
    ?>
    admin/product_create.php
    Code:
    <h1><?php echo $title;?></h1>
    <?php
    echo form_open_multipart('admin/produk/create');
    echo 
    "<p><label for='parent'>Category</label><br/>";
    echo 
    form_dropdown('cat_id',$categories) ."</p>";

    echo 
    "<p><label for='name'>Name</label><br/>";
    $data = array('name'=>'nama','id'=>'nama','size'=>25);
    echo 
    form_input($data) ."</p>";

    echo 
    "<p><label for='short'>Short Description</label><br/>";
    $data = array('name'=>'shortdesc','id'=>'short','size'=>40);
    echo 
    form_input($data) ."</p>";

    echo 
    "<p><label for='long'>Long Description</label><br/>";
    $data = array('name'=>'longdesc','id'=>'long','rows'=>5'cols'=>'40');
    echo 
    form_textarea($data) ."</p>";

    echo 
    "<p><label for='uimage'>Upload Image</label><br/>";
    $data = array('name'=>'image','id'=>'uimage');
    echo 
    form_upload($data) ."</p>";

    echo 
    "<p><label for='uthumb'>Upload Thumbnail</label><br/>";
    $data = array('name'=>'thumbnail','id'=>'uthumb');
    echo 
    form_upload($data) ."</p>";

    echo 
    "<p><label for='harga'>Harga</label><br/>";
    $data = array('name'=>'harga','id'=>'harga','size'=>10);
    echo 
    form_input($data) ."</p>";

    echo 
    "<p><label for='diskon'>diskon(%)</label><br/>";
    $data = array('name'=>'diskon','id'=>'diskon','size'=>10);
    echo 
    form_input($data) ."</p>";

    echo 
    "<p><label for='harga_diskon' >Harga Diskon</label><br/>";
    $data = array('name'=>'harga_diskon','id'=>'harga_diskon','size'=>10);
    echo 
    form_input($harga_diskon) ."</p>";

    echo 
    "<p><label for='status'>Status</label><br/>";
    $options = array('active' => 'active''inactive' => 'inactive');
    echo 
    form_dropdown('status',$options) ."</p>";

    echo 
    "<p><label for='featured'>Featured</label><br/>";
    $options = array('Y' => 'Y''N' => 'N');
    echo 
    form_dropdown('featured',$options) ."</p>";

    echo 
    "<p><label for='new'>New</label><br/>";
    $options = array('Y' => 'Y''N' => 'N');
    echo 
    form_dropdown('baru',$options) ."</p>";

    echo 
    "<p><label for='promo'>Promo</label><br/>";
    $options = array('Y' => 'Y''N' => 'N');
    echo 
    form_dropdown('promosi',$options) ."</p>";

    echo 
    form_submit('submit','create product');
    echo 
    form_close();
    ?>
    and the Produk controller

    Code:
     function index()
      {
        
    $data['title'] = "Manage Products";
        
    $data['main'] = 'admin/product_home';
        
    $data['products'] = $this->MProduk->getAllProducts();
        
    $data['categories'] = $this->MCat->getCategoriesDropDown();
        
    $this->load->vars($data);
        
    $this->load->view('dashboard');
      }
      
      function 
    create(){
           if (
    $this->input->post('nama')){
               
    $this->MProduk->addProduct();
              
    $this->session->set_flashdata('message','Product created');
              
    redirect('admin/produk/index','refresh');
          }else
        {
            
    $data['title'] = "Create Product";
            
    $data['main'] = 'admin/product_create';
            
    $data['categories'] = $this->MCat->getCategoriesDropDown();
            
    $this->load->vars($data);
            
    $this->load->view('dashboard');    
        } 
      } 

    I'm intending to automatically fill the harga_diskon field with the calculated value from harga-diskon/100.

    This is js script

    Code:
    <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
       
       $("#diskon").change(function()
       {
           var price = parseInt($("#harga").val());
           var discount = parseInt($("#diskon").val());
    
           var discounted_price = harga * (diskon/100);
           
           //alert(price + " + " + discount + " = " + discounted_price);
           $("#harga_diskon").val(discounted_price);
           return false;
       });
    });
    </script>
    I try to put the js on the view page,it doesn't give me the expected results.Can someone tell me how to properly do it?And where should i put the js scripts?Thanks a lot...

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: codeigniter with jquery

    JavaScript can go anywhere on your page but is most commonly found between your <head></head> tags. I don't see those in your PHP/HTML. Are you including a header or footer file somewhere?

    Also, what does form_input() do? Does it just produce a text based input?

  4. #3
    yonghan is offline Learning Programmer
    Join Date
    May 2008
    Posts
    99
    Rep Power
    0

    Re: codeigniter with jquery

    Yes Jordan,i'm using a header file. form_input() is the same as text based input..

  5. #4
    yonghan is offline Learning Programmer
    Join Date
    May 2008
    Posts
    99
    Rep Power
    0

    Re: codeigniter with jquery

    By the way,i got it worked out already..Thanks Jordan..

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 04-22-2011, 11:18 AM
  2. Replies: 13
    Last Post: 01-22-2011, 10:33 AM
  3. Replies: 2
    Last Post: 01-15-2011, 06:15 PM
  4. CakePHP vs. CodeIgniter
    By Roger in forum PHP Development
    Replies: 5
    Last Post: 11-30-2010, 10:37 AM
  5. form action with codeigniter
    By coder25 in forum PHP Development
    Replies: 0
    Last Post: 11-14-2010, 08:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts