OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to Call Onload Function inside table td tag

  • Thread starter Thread starter Kavya Shree
  • Start date Start date
K

Kavya Shree

Guest
Hiii Everone,

I want to check the condition while load td tag.SO that i tried to check the condition with the help of onload function.Below is the example but the code which i tried inside onload is not working please any one help me to get out of this problem.Sceneraio is inside td there will be two button if the condition inside check_course is greater than 1 it will show button 1 or else button 2.

PHP Code

Code:
<?php 
date_default_timezone_set('Asia/Kolkata');
$date = date("Y-m-d");
$time = date("Y-m-d H:i:s");
require "country.php";
$per_email=$_POST['per_email'];
$stream_name=$_POST['specialization_filter'];
$country_filter=$_POST['country_filter'];
$country = new country();
$users = $country->universities($stream_name,$country_filter);

if ( empty($users) ) {
?>
<br/><br/>
   <?php       echo "<span class=\"alert alert-danger\">No universities Available For Your Search Results!!! </span> <br>" ;

}else{

 ?>
<div class="table-responsive" id="filter_universities">
<table class="table no-border">
<thead >
<tr class="row_univ">
<th class="university_sort" id="name_total_sort" status="asc" style="cursor:pointer">University 
<i class="fa fa-caret-down font-grey-salsa"></i>
</th>
<th class="col-md-3">Program</th>
<th class="fee_structure" id="fee_total_sort" status="asc" style="cursor:pointer">Fee 
<i class="fa fa-caret-down font-grey-salsa"></i>
</th>
</tr>
</thead>
<tbody>
<?php
 $i=0;
  foreach ($users as $user){ 
   $i++;
?>
        <tr class="tr_bgs">
        <td class="col-md-4">
        <div class="row">
        <div class="col-md-3">
        <img src="images/university1.jpg" class="img-circle" width="62px" height="62px" alt="">
        </div>
        <div class="col-md-9">
        <h5 class="bold fees">
        <a target="_blank" class="university_class" mode="ambitious" cid="292"><?php echo $user['university']?> </a>
        </h5>
        <span class="font-grey-lite"><?php echo $user['country']?> </span>
        </div>
        </div>
        </td>
        <td>
        <h5 class="bold fees">  <?php echo $user['course']?> </h5>
        <span class="font-grey-lite"> <?php echo $user['stream_name']?> </span>
        </td>
        <td>
        <h5 class="bold fees"><?php echo $user['fees']?> </h5>
        <span class="font-grey-lite">Per Year</span>
        </td>
        <td class="text-center" id="course_button" onload="check_course(<?php echo $user['id']?>);">

 <div id="added_course<?php echo $user['id']?>"><br/><button type="button" class="btn btn-primary" onClick="delete_course_list(<?php echo $user['id']?>);">
 <i class="fa fa-star" aria-hidden="true"></i>&nbsp;Course Added</button></div>

 <div id="add_course<?php echo $user['id']?>">              
 <br/><button type="button" class="btn btn-primary" 
 onClick="save_course_list(<?php echo $user['id']?>);">
 <i class="fa fa-star-o" aria-hidden="true"></i>&nbsp;Add to My Course</button></div>
</td>
</tr>   
<tr class="row_univ tr_bgs">
<td colspan="6">
<table class="table no-border no-margin text-grey">
<tbody>
<tr class="tr_bgs">

</tr>
</tbody>
</table>
</td>
</tr>  
<?php
 } 
          }  ?>
</tbody>
</table>
</div>

Script

Code:
function check_course(variable)
  {
    var course_id=str;
    var per_email= '<?php echo $per_email; ?>' ;
    var datas="&course_id="+course_id+"&per_email="+per_email;
    alert(datas);
   $.ajax({
    type: "POST",
    url: 'php/country/check_course.php',
    data:datas
    }).done(function( data ) 
    {
      alert(data);
      if(data>0)
      {
          $('#added_course'+str).show();
          $('#add_course'+str).hide(); 
      }
      else
      {
       $('#add_course'+str).show(); 
       $('#added_course'+str).hide();
       }

      });

  }

What mistake i did is there any syntax problem with this.Please help me.Thanks in advance.

<p>Hiii Everone,</p>

<p>I want to check the condition while load td tag.SO that i tried to check the condition with the help of onload function.Below is the example but the code which i tried inside onload is not working please any one help me to get out of this problem.Sceneraio is inside td there will be two button if the condition inside check_course is greater than 1 it will show button 1 or else button 2.</p>

<p>PHP Code</p>

<pre><code><?php
date_default_timezone_set('Asia/Kolkata');
$date = date("Y-m-d");
$time = date("Y-m-d H:i:s");
require "country.php";
$per_email=$_POST['per_email'];
$stream_name=$_POST['specialization_filter'];
$country_filter=$_POST['country_filter'];
$country = new country();
$users = $country->universities($stream_name,$country_filter);

if ( empty($users) ) {
?>
<br/><br/>
<?php echo "<span class=\"alert alert-danger\">No universities Available For Your Search Results!!! </span> <br>" ;

}else{

?>
<div class="table-responsive" id="filter_universities">
<table class="table no-border">
<thead >
<tr class="row_univ">
<th class="university_sort" id="name_total_sort" status="asc" style="cursor:pointer">University
<i class="fa fa-caret-down font-grey-salsa"></i>
</th>
<th class="col-md-3">Program</th>
<th class="fee_structure" id="fee_total_sort" status="asc" style="cursor:pointer">Fee
<i class="fa fa-caret-down font-grey-salsa"></i>
</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
foreach ($users as $user){
$i++;
?>
<tr class="tr_bgs">
<td class="col-md-4">
<div class="row">
<div class="col-md-3">
<img src="images/university1.jpg" class="img-circle" width="62px" height="62px" alt="">
</div>
<div class="col-md-9">
<h5 class="bold fees">
<a target="_blank" class="university_class" mode="ambitious" cid="292"><?php echo $user['university']?> </a>
</h5>
<span class="font-grey-lite"><?php echo $user['country']?> </span>
</div>
</div>
</td>
<td>
<h5 class="bold fees"> <?php echo $user['course']?> </h5>
<span class="font-grey-lite"> <?php echo $user['stream_name']?> </span>
</td>
<td>
<h5 class="bold fees"><?php echo $user['fees']?> </h5>
<span class="font-grey-lite">Per Year</span>
</td>
<td class="text-center" id="course_button" onload="check_course(<?php echo $user['id']?>);">

<div id="added_course<?php echo $user['id']?>"><br/><button type="button" class="btn btn-primary" onClick="delete_course_list(<?php echo $user['id']?>);">
<i class="fa fa-star" aria-hidden="true"></i>&nbsp;Course Added</button></div>

<div id="add_course<?php echo $user['id']?>">
<br/><button type="button" class="btn btn-primary"
onClick="save_course_list(<?php echo $user['id']?>);">
<i class="fa fa-star-o" aria-hidden="true"></i>&nbsp;Add to My Course</button></div>
</td>
</tr>
<tr class="row_univ tr_bgs">
<td colspan="6">
<table class="table no-border no-margin text-grey">
<tbody>
<tr class="tr_bgs">

</tr>
</tbody>
</table>
</td>
</tr>
<?php
}
} ?>
</tbody>
</table>
</div>
</code></pre>

<p>Script</p>

<pre><code>function check_course(variable)
{
var course_id=str;
var per_email= '<?php echo $per_email; ?>' ;
var datas="&course_id="+course_id+"&per_email="+per_email;
alert(datas);
$.ajax({
type: "POST",
url: 'php/country/check_course.php',
data:datas
}).done(function( data )
{
alert(data);
if(data>0)
{
$('#added_course'+str).show();
$('#add_course'+str).hide();
}
else
{
$('#add_course'+str).show();
$('#added_course'+str).hide();
}

});

}
</code></pre>

<p>What mistake i did is there any syntax problem with this.Please help me.Thanks in advance.</p>
 

Latest posts

Top