Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. $(document).ready(function() {
  2. $('#myselect').change(function(e) {
  3. if ($(this).val() == "addother") {
  4.  
  5. $('#addother').show();
  6.  
  7. $('#addother_input').val('');
  8.  
  9. } else {
  10. $('#addother').hide();
  11. }
  12. });
  13.  
  14. $('#add').click(function() {
  15. $.ajax({
  16. type: "POST",
  17. url: window.location,// use ci url here(i.e call controller)
  18. data: { selectboxvalue: $('#addother_input').val('') } ///value will be sent
  19. })
  20. .done(function( msg ) {
  21. $('#add').html(msg);
  22. });
  23. });
  24.  
  25.  
  26. });
  27.  
  28. </script>
  29.  
  30. </head>
  31. <body>
  32.  
  33. <div id="container">
  34.  
  35.  
  36. <?php echo form_open('form/myform'); ?>
  37.  
  38. <?php
  39.  
  40. $options = array(
  41. 'school' => $row->school ,
  42. 'addother' => 'Add other...'
  43. );
  44.  
  45.  
  46. echo form_dropdown('shirts', $options, null, 'id="myselect"');
  47.  
  48. ?>
  49.  
  50. <div id="addother">
  51. <?php echo form_input(array('id'=>'addother_input', 'name'=>'school', 'placeholder'=>'Enter name of school...')); ?>
  52. <input type="submit" id="add" name="submit" value="+" />
  53. </div>
  54.  
  55. <?php echo form_close(); ?>
  56. </div>
  57.  
  58. function myform(){
  59. $data['title'] = "myform";
  60.  
  61. $this->load->library('form_validation');
  62.  
  63. $this->load->model('school_model');
  64.  
  65. $sdata['school'] = $this->input->post('school');
  66.  
  67. $this->school_model->addItem($sdata);
  68.  
  69. $this->load->view('myform');
  70.  
  71. }
  72.  
  73. function drop() {
  74. $this->load->model('school_model');
  75.  
  76. $data['options'] = $this->school_model->getAll();
  77.  
  78. $this->load->view('myform', $data);
  79. }
  80.  
  81. function getAll() {
  82.  
  83. $this->db->select('school');
  84.  
  85. $this->db->from('tblschool');
  86.  
  87. $query = $this->db->get();
  88.  
  89. return $query->result();
  90.  
  91. }
  92.  
  93.  
  94. function addItem($sdata){
  95.  
  96. return $this->db->insert('tblschool', $sdata);
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement