Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $('#myselect').change(function(e) {
- if ($(this).val() == "addother") {
- $('#addother').show();
- $('#addother_input').val('');
- } else {
- $('#addother').hide();
- }
- });
- $('#add').click(function() {
- $.ajax({
- type: "POST",
- url: window.location,// use ci url here(i.e call controller)
- data: { selectboxvalue: $('#addother_input').val('') } ///value will be sent
- })
- .done(function( msg ) {
- $('#add').html(msg);
- });
- });
- });
- </script>
- </head>
- <body>
- <div id="container">
- <?php echo form_open('form/myform'); ?>
- <?php
- $options = array(
- 'school' => $row->school ,
- 'addother' => 'Add other...'
- );
- echo form_dropdown('shirts', $options, null, 'id="myselect"');
- ?>
- <div id="addother">
- <?php echo form_input(array('id'=>'addother_input', 'name'=>'school', 'placeholder'=>'Enter name of school...')); ?>
- <input type="submit" id="add" name="submit" value="+" />
- </div>
- <?php echo form_close(); ?>
- </div>
- function myform(){
- $data['title'] = "myform";
- $this->load->library('form_validation');
- $this->load->model('school_model');
- $sdata['school'] = $this->input->post('school');
- $this->school_model->addItem($sdata);
- $this->load->view('myform');
- }
- function drop() {
- $this->load->model('school_model');
- $data['options'] = $this->school_model->getAll();
- $this->load->view('myform', $data);
- }
- function getAll() {
- $this->db->select('school');
- $this->db->from('tblschool');
- $query = $this->db->get();
- return $query->result();
- }
- function addItem($sdata){
- return $this->db->insert('tblschool', $sdata);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement