2 Replies - 3129 Views - Last Post: 18 April 2010 - 11:40 AM

#1 whizzell   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 31-July 08

Insert tr then Hide/Show Toggle

Posted 16 April 2010 - 08:00 AM

I have a page with a table on it. The table is generated dynamically with PHP. It shows the courses types. I.e. NVQ 1, 2, 3 and Others

I then want to display the users on each course underneath.

I was doing this with Jquery. I'm sure there is a way to do it using PHP but I liked the idea of it loading faster and the drop-down toggle.

The JQuery I have is:
function show_learners(type_ID) {
	var type_ID = type_ID;
	
// send data check

	var dataString =  'type_ID=' + type_ID;
	//alert (dataString);return false;  
				$.ajax({  
				type: "POST",  
             	url: "../php/get_course_users_details.php",   
				data: dataString,
				cache: false,  
				success: function(html) {  
				//display message back to user here 
					
				var result = html.charAt(0);
				var data = html.substring(2);

				//if ../php/get_course_users_details.php returned 1/true  
					if (result = 1) {
									
					var nextid = type_ID + 1;
					$('#' + type_ID + ' .rightdd').attr('src', '/kmt/admin/img/dd2-icon.gif');
					$(data).insertBefore($('#' + nextid));
					var shown = 1;
					
					}

				//if ../php/get_course_users_details.php returned 0/false  
					if (result = 0) {
					
					return false;
					
					}
				// Do anything else
}
});
}

function hide_learners(type_ID) {
					$('#' + type_ID + ' .bg').hide();
					$('#' + type_ID + ' .rightdd').attr('src', '/kmt/admin/img/dd-icon.gif');
					var shown = 0;
}



the returned information in variable data is:
<tr id="3" class="bg">
<td class="first style2">- Testing user</td>
<td> Hairdressing and Barbering </td>
<td>20%</td>
<td><img src="img/login-icon.gif" width="16" height="16" alt="View user profile" /></td>
<td>09/04/2010</td>
</tr>



the page it displays on is:
<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="177">Users</th>
						<th>Course</th>
						<th>Progress</th>
						<th>Profile</th>
						<th class="last">Last Updated</th>
					</tr>
                    
                    <?php do { ?>
					<tr id="<?php echo $row_all_course_data['type_ID'];?>">
						<td colspan="5" id="<?php echo $row_all_course_data['type_ID'];?>" class="first style1">- <?php echo $row_all_course_data['type_name'];?>'s<img id="<?php echo $row_all_course_data['type_ID'];?>" class="rightdd" src="/kmt/admin/img/dd-icon.gif" width="14" height="14" /></td>
					</tr>
                    <?php } while ($row_all_course_data = mysql_fetch_assoc($all_course_data)); ?>

				</table>



Anyone able to help my get the hide_learners function to actually hide the inserted rows. I also need a way to stop show_learners running everytime its clicked.

thanks Will

Is This A Good Question/Topic? 0
  • +

Replies To: Insert tr then Hide/Show Toggle

#2 oomlaut   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 27
  • Joined: 07-April 09

Re: Insert tr then Hide/Show Toggle

Posted 16 April 2010 - 01:32 PM

Do you have a link to this functionality? It would be more helpful to see the misbehavior than just the code snippets?
Was This Post Helpful? 0
  • +
  • -

#3 Fratyr   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 139
  • Joined: 10-April 08

Re: Insert tr then Hide/Show Toggle

Posted 18 April 2010 - 11:40 AM

Or you could ask your question clearly.

As I understand from the subject name, take a look at those:
adding item AFTER selected element: $('#id_of_element').append('<html code>');
this will append a new element after 'id_of_element' it can be a table, so the code will be added as the last <tr> if you decide to append <tr>

Showing/Hiding elements: $('#element').hide(); AND $('#element').show();
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1