zachvaldez
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,et c.
I'd like to hide 6 to 11 if mo data entered and display if there is.
I'd like to hide 6 to 11 if mo data entered and display if there is.
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?
Where is data coming from?
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.
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.
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.
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.
ASKER
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.
In your style definitions, set display to "none" for tr elements of that class.
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 class="enrollForm">...</tr>
In your style definitions, set display to "none" for tr elements of that class.
tr.enrollForm { display: none }
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");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can you expand o this approach? I like this propose solution
("tr.enrollForm").css("dis play", $("tr.enrollForm").css("di splay") == "none" ? "" : "none");
("tr.enrollForm").css("dis
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?
Looks like you are saying if display is set to none then set display to none - sort of redundant?
ASKER
Do you recommend server side or JavaScript?
Server side is a lot simpler.
ASKER
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
}
You need to provide more info on the specifics of what you are trying to do.
ASKER
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!!!