handoyo Posted October 11, 2009 Share Posted October 11, 2009 Hi all,i got codes in CI views like this admin/product_home.php <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 " "; echo "</p>"; echo "<table border='1' cellspacing='0' cellpadding='3' width='500'>\n"; echo "<tr valign='top'>\n"; echo "<th> </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 <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 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 <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... Quote Link to comment https://forums.phpfreaks.com/topic/177306-codeigniter-with-jquery/ Share on other sites More sharing options...
GKWelding Posted October 12, 2009 Share Posted October 12, 2009 Honestly, you can put the JS wherever you like when you're incluyding it in that way (which is also the way I include it in my CI applications), there is no right or wrong way of including jQuery into CI. however, I'm not quite sure what your problem is, are you getting an incorrect value back after the calculation? Quote Link to comment https://forums.phpfreaks.com/topic/177306-codeigniter-with-jquery/#findComment-935342 Share on other sites More sharing options...
handoyo Posted October 12, 2009 Author Share Posted October 12, 2009 I did not get the value GK..Usually what cause the js don't work?Thanks GKWelding.. Quote Link to comment https://forums.phpfreaks.com/topic/177306-codeigniter-with-jquery/#findComment-935586 Share on other sites More sharing options...
handoyo Posted October 13, 2009 Author Share Posted October 13, 2009 I got i working GKWelding,i got a mistake with echo form_input($harga_diskon) ."</p>"; It should be echo form_input($data) ."</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/177306-codeigniter-with-jquery/#findComment-936055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.