Welcome Guest, Not a member yet? Register   Sign In
Event handling
#1

Hello,

I have 2 divs. first is to accept some values and second is to display the output on the basis of inputs in div1.

The form is working fine. 
My requirement is, on submitting (button in div1) , div1 should move to left side and div 2 should display the result adjacent to div1  .

My JQuery code is shifting the div1 to left but data is not posting to the controller .


in the view 

echo form_open('flights_cont/view_flight_details', array( 'id' => 'myform'));?>

<script type="text/javascript">

 $(function()
        {

$('#myform').submit(function(e)
    {
    e.preventDefault();
    var dataString = $("#myform").serialize();
    $.ajax
    ({
        type:"POST",
        url:"<?php echo 'view_flight_details'?>",
        data: dataString
        }); 
            $( "#submain" ).css('margin-left','10px');
      });
     
    });
Reply
#2

PHP Code:
url:"<?php echo base_url('controller/method');?>"
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 06-03-2020, 10:22 AM by jreklund.)

(05-26-2020, 03:48 AM)InsiteFX Wrote:
PHP Code:
url:"<?php echo base_url('controller/method');?>"
Hello Sir,

No, it is not working. i used the concept in html page, it is working fine. Is it something related to reloading or refreshing of form in CI?
CI view page is like this 
PHP Code:
<body> 
<div id="main"> 
<div id="submain">
<
a href="logout" style="float:right;color:darkblue;"Logout</a>
<
h1>Flight Details</h1>
<
hr/>
<?
php if(isset($error_message)){?>
      <div class="error_msg">
            <?php echo $error_message?>
      </div>
    <?php }

echo 
form_open('flights_cont/view_flight_details', array( 'id' => 'myform'));?>

<label>From City :</label>
<input type="text" name="txtFrCity" id="idFrCity" placeholder="Departure From"><br>
<?php echo form_error('txtFrCity''<div class="error_msg">',
'</div>'); ?><br>
<label>To City :</label>
<input type="text" name="txtToCity" id="idToCity" placeholder="Arrival To"><br>
<?php echo form_error('txtToCity''<div class="error_msg">',
'</div>'); ?><br />
<label>Slot :</label>
<select name="slot">
<option value="04:00:00 To 06:59:59">
Early Morning</option>
<option value="07:00:00 To 11:59:00">Morning</option>
<option value="12:00:00  To 15:59:00">Afternoon</option>
<option value="16:00:00 To 19:59:00">Evening</option>
<option value="20:00:00 To 23:59:00">Night</option>
<option value="24:00:00 AM To 03:59:00">Late Night</option>
</select> <br>
<br>
<input type="submit" value="Check" name="check"><br>


</div> 
<!--<div id="submain2"> -->
<?php 
if (isset($_POST['check'])) 
{?>
<div id="submain2">
<?php 
foreach($info->result() as $row) : { ?>

<p><?php echo $row->flight_number?></p>
<table border="" rules="all">
<tr>
<th>From City</th>
<th>To City</th>
<th>Departure</th>
<th>Arrival</th>
<th>Price</th>
<th>Stopage</th>
<th>Book Ticket</th>
</tr>

<tr>
<td> <?php echo $row->from_city?> </td>
<td> <?php echo $row->to_city?> </td>
<td> <?php echo $row->departure_time?> </td>
<td> <?php echo $row->arrival_time?> </td>
<td> <?php echo $row->price?> </td>
<td> <?php echo $row->stopage?> </td>
<td><a href="booking_form"> Book </a></td>
</tr>
</table>

<?php 
} endforeach;?>
</div>
<?php }
?>
<!--</div>-->
</div>
<script type="text/javascript">

        $(function()
        {

$('#myform').submit(function(e)
    {
    // e.preventDefault();
    var dataString = $("#myform").serialize();
    $.ajax
    ({
        type:"POST",
        url:"<?php echo 'flights_cont/view_flight_details'?>",
        data: dataString
        });  
            $( "#submain" ).css({
"marginLeft": "-10px",
});
            });
      
    });


</script>
</body>
</html> 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB