Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum
Register Blogs Search Today's Posts Mark Forums Read

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-11-2009, 07:58 AM
Learning Programmer
 
Join Date: May 2008
Posts: 96
yonghan is an unknown quantity at this point
codeigniter with jquery

Hi all,i got codes in CI views like this

admin/product_home.php
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
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

PHP 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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-11-2009, 09:00 AM
Jordan's Avatar
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 24,556
Jordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to all
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-11-2009, 09:09 AM
Learning Programmer
 
Join Date: May 2008
Posts: 96
yonghan is an unknown quantity at this point
Re: codeigniter with jquery

Yes Jordan,i'm using a header file. form_input() is the same as text based input..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-15-2009, 01:08 PM
Learning Programmer
 
Join Date: May 2008
Posts: 96
yonghan is an unknown quantity at this point
Re: codeigniter with jquery

By the way,i got it worked out already..Thanks Jordan..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
jquery slideup problem jwxie518 JavaScript and CSS 1 10-04-2009 12:26 PM
jQuery: Validation Brandon W Javascript 9 03-02-2009 04:19 PM
jQuery: Events Brandon W Javascript 10 02-28-2009 05:54 AM
jQuery: Zebra striped table Brandon W Javascript 13 02-26-2009 04:29 PM
jQuery: Selectors Brandon W Javascript 8 02-26-2009 08:23 AM


All times are GMT -5. The time now is 11:39 PM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0