+ Reply to Thread
Results 1 to 4 of 4

Thread: codeigniter with jquery

  1. #1
    Learning Programmer yonghan is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    96

    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. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    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?

  3. #3
    Learning Programmer yonghan is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    96

    Re: codeigniter with jquery

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

  4. #4
    Learning Programmer yonghan is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    96

    Re: codeigniter with jquery

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. jquery slideup problem
    By jwxie518 in forum JavaScript and CSS
    Replies: 1
    Last Post: 10-04-2009, 11:26 AM
  2. jQuery: Validation
    By Brandon W in forum Javascript
    Replies: 9
    Last Post: 03-02-2009, 03:19 PM
  3. jQuery: Events
    By Brandon W in forum Javascript
    Replies: 10
    Last Post: 02-28-2009, 04:54 AM
  4. jQuery: Zebra striped table
    By Brandon W in forum Javascript
    Replies: 13
    Last Post: 02-26-2009, 03:29 PM
  5. jQuery: Selectors
    By Brandon W in forum Javascript
    Replies: 8
    Last Post: 02-26-2009, 07:23 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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