Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on

hide rows in a table

I created a table,tr's and td's to display data.The first 5 rows are student personal info like name,address,gender,etc. From row 6 to 11 asked for student enrollment info like course,subject,schedule,etc.
I'd like to hide 6 to 11 if mo data entered and display if there is.
Avatar of Kyle Hamilton
Kyle Hamilton
Flag of United States of America image

do you want to do this with javascript or server side?
I assume you're pulling data from some type of database and then populating values into JavaScript variables?

Where is data coming from?
Avatar of Julian Hansen
Assuming you have a record you are working with - don't know what that is so will use generic

if (row[course] != '')
   output <td>row[course]</td>
else
   don't

The question is - do you want the rows to be there but just not visibile in which case you can add a class to the <tr class="hideme"> and then use

.hideme {display: none;}

To turn them off

OR

Do you not wish to output the row at all if the data is empty in which case you need to test your data and if empty don't output.

Without knowing more about your code can't really offer more than that.
Avatar of zachvaldez

ASKER

in the page I have a button,it opens another page where the Student enrollment details are entered and saved. When the previous page is open this data  is seen in that page( this part I know how to display the data) When data is not entered in the 2nd page, the first page will hide the rows where the data should display.
So technically, when the page is open for the first time, rows 6 to 11 will be hide cause no data has been read for that ID, but will only display if data has been entered in the 2nd page. This part is read from the database so it will populate the first page.
can you show javascript and server side? which is practical and easy to implement?
The best way to do this would be to assign a class specific to those rows you want to show and hide dynamically. Each row of the form would have that class assigned.
<tr class="enrollForm">...</tr>

Open in new window


In your style definitions, set display to "none" for tr elements of that class.
tr.enrollForm { display: none }

Open in new window


You can then use JavaScript to set the display style for each row with that class whenever the button is clicked. jQuery makes this easy and the code below shows how.
$("tr.enrollForm").css("display", $("tr.enrollForm").css("display") == "none" ? "" : "none");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you expand o this approach? I like this propose solution

("tr.enrollForm").css("display", $("tr.enrollForm").css("display") == "none" ? "" : "none");
What are you trying to achieve with that line?

Looks like you are saying if display is set to none then set display to none - sort of redundant?
Do you recommend server side or JavaScript?
Server side is a lot simpler.
Can you provide more details in your code julianH?
What details do you need - you need to give us more information about your application - I have outlined the basicis of what you can do in an earlier post which is
$data = get_data_from_db();
// output the rows that you want based on some condition
echo "
<tr>
  <td>Row1" . $data['somefield'] . "</td>
</tr> ";
...
if ($data['somevalue'] != "")  {
   // output other rows
}

Open in new window

You need to provide more info on the specifics of what you are trying to do.
Not the best solution
Not the best solution
!!!
Did you see my last post
You need to provide more info on the specifics of what you are trying to do.
I can only assist you based on the input you give me!!!