Welcome Guest, Not a member yet? Register   Sign In
[Solved] Onclick not working with php code
#1

(This post was last modified: 12-23-2015, 04:02 PM by wolfgang1983.)

I am using calendar library and I can get data displayed on my dates from database in my array on model.

Where I have $calendar[$event['day']] = I can return html code also for calendar view data.

The on click is not working correct it is still submitting the form when I click on cancel? Why would it do that and how to fix it?

Example:


PHP Code:
<?php

    public 
function get_events($year$month) {
 
       $calendar = array();

 
       $this->db->where('year'$year);
 
       $this->db->where('month'$month);
 
       $query $this->db->get('calendar');

 
       $results $query->result_array();

 
       foreach ($results as $event) {

 
           if (array_key_exists($event['day'], $calendar)) {


 
                   
                $calendar
[$event['day']] =     $calendar[$event['day']] .'
                                            <div class="clearfix">
                                            <div class="pull-left">
                                            <ul class="list-unstyled">
                                            <li>'
 
                                           anchor(base_url('report/events/'$year .'/'$month .'/'$event['calendar_id']), $event['event']) . '
                                            </li>
                                            </ul>
                                            </div>
                                            <div class="pull-right">'
 
                                           .anchor(base_url('report/events/edit' .'/'$event['calendar_id']), '<i class="fa fa-pencil"></i>', array('class' => 'text-primary''data-toggle' => 'tooltip'' data-placement' => 'top''title' => 'Edit Event')).'
                                            
                                            <i type="button" onclick="confirm(\'Are you sure?\') ? $(\'#form-event\').submit() : false;" class="fa fa-trash text-danger" style="cursor: pointer;"></i>

                                            <form id="form-event" method="post" enctype="multipart/form-data" id="form-user">
                                            <input type="hidden" name="delete_id" value="'
.$event['calendar_id'].'">
                                            </form>
        
                                            </div>
                                            </div>'
;
 
               
            
} else {
 
               
                $calendar
[$event['day']] = '<div class="clearfix">
                                            <div class="pull-left">
                                            <ul class="list-unstyled">
                                            <li>' 
 
                                           anchor(base_url('report/events/'$year .'/'$month .'/'$event['calendar_id']), $event['event']) . '
                                            </li>
                                            </ul>
                                            </div>
                                            <div class="pull-right">'
 
                                           .anchor(base_url('report/events/edit' .'/'$event['calendar_id']), '<i class="fa fa-pencil"></i>', array('class' => 'text-primary''data-toggle' => 'tooltip'' data-placement' => 'top''title' => 'Edit Event')).'
                                    
                                            <i type="button" onclick="confirm(\'Are you sure?\') ? $(\'#form-event\').submit() : false;" class="fa fa-trash text-danger" style="cursor: pointer;"></i>

                                            <form id="form-event" method="post" enctype="multipart/form-data" id="form-user">
                                            <input type="hidden" name="delete_id" value="'
.$event['calendar_id'].'">
                                            </form>
        
                                            </div>
                                            </div>'
;
 
           }
 
       }

 
       return $calendar;
 
   


Attached Files Thumbnail(s)
   

.php   example.php (Size: 2.94 KB / Downloads: 146)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

I found best method for me. On the form open add on submit.




<form id="form-event" method="post" enctype="multipart/form-data" onsubmit="return confirm(\'Are you sure you want to remove this!\')";>
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB