/    Sign up×
Community /Pin to ProfileBookmark

Show / Hide Table Rows

I wish to show / hide table rows on my table based on the press of a button, and the default is to be hidden. here is what I have currently:

[code]
<span id=”spanQuoteInfo<%=i%>” style=”display: none”>
<tr>
<th></th>
<th nowrap><font face=”verdana” size=”1″>Quote Number</font></th>
<th><font face=”verdana” size=”1″>Part #</font></th>
<th nowrap><font face=”verdana” size=”1″>Cust Min Qty</font></th>
<th><font face=”verdana” size=”1″>Price</font></th>
<th><font face=”verdana” size=”1″>Date</font></th>
</tr>
<%
set rs1 = Server.CreateObject (“adodb.RecordSet”)
ssql = “SELECT QUOTES.[QUOTE #] AS Quote, [QUOTES DETAIL].CustMinQty, [QUOTES DETAIL].PRICE, QUOTES.[DATE] AS QuoteDate”
ssql = ssql & ” FROM [QUOTES DETAIL] INNER JOIN QUOTES ON [QUOTES DETAIL].[QUOTE #] = QUOTES.[QUOTE #]”
ssql = ssql & ” WHERE (QUOTES.CustNbr = ‘”&strCustNum &”‘) AND ([QUOTES DETAIL].[PART #] = ‘”&rs(“PartNum”)&”‘)”
rs1.Open ssql, dbc, adOpenForwardOnly, adLockReadOnly

do while not rs1.eof
%>
<tr>
<td></td>
<td><font face=”verdana” size=”1″><a href=”Quote_Info1-ajax.asp?CustNum=<%=strCustNum%>&QuoteNum=<%=rs1(“Quote”)%>”><%=rs1(“Quote”)%></font>&nbsp;</td>
<td><font face=”verdana” size=”1″><%=rs(“PartNum”)%></font>&nbsp;</td>
<td><font face=”verdana” size=”1″><%=rs1(“CustMinQty”)%></font>&nbsp;</td>
<td><font face=”verdana” size=”1″><%=rs1(“PRICE”)%></font>&nbsp;</td>
<td nowrap><font face=”verdana” size=”1″><%=rs1(“QuoteDate”)%></font>&nbsp;</td>
<%
rs1.moveNext
Loop

rs1.close
set rs1=nothing
%>
</span>
[/code]

However, that code shows the information on default, it is not hiding it. I am guessing this is because a span can’t hide a table row or something like that.

So, how would I go about hiding the appropriate rows? Something like this?

<tr id=”QuoteHeader”>
for the header portion

<tr id=”QuoteDetails<%=i%>”>
for the details portion and I would have a counter for i

Have them all default to hidden

then, when show is clicked, it would show everything…here is my show code which fails currently…i get object exptected error:

[code]
function ShowQuoteInfo(i)
{
var strShowQuoteInfo = document.getElementById(“spanShowQuoteInfo” + i)

strShowQuoteInfo.style.display = (strShowQuoteInfo.style.display && strShowQuoteInfo.style.display==’block’ ? ‘none’ : ‘block’);
}
[/code]

this is when I press this button:

[code]
<td><input type=”button” value=”show/hide” onClick=”ShowQuoteInfo(<%=i%>)” style=”font-family: Verdana; font-size: 7pt”></td>
[/code]

can someone help me figure this out?

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyFeb 07.2009 — Yes, to hide parts of a table, you should [B]style[/B] the desired row (TR) element to [B]display="none"[/B] to hide that row. Then, style it to [B]display=""[/B] to show it again.
Copy linkTweet thisAlerts:
@dzirkelbauthorFeb 09.2009 — That works great...thanks!

Now, I need a little help placing this in a a loop to display...it needs to show something like this:

<i>
</i>function ShowQuoteInfo(i, intCountOfQuotes)
{
var strShowQuoteInfoHeader = document.getElementById("trQuoteInfoHeader" + i)
strShowQuoteInfoHeader.style.display = (strShowQuoteInfoHeader.style.display &amp;&amp; strShowQuoteInfoHeader.style.display=='block' ? 'none' : 'block');

for r = 0 to intCountOfQuotes
var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails" + r)
strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
next
}

How can I place that into javascript with the correct syntax?


}
Copy linkTweet thisAlerts:
@MrNobodyFeb 09.2009 — Something like this:
[CODE]function ShowQuoteInfo(i, intCountOfQuotes)
{
var strShowQuoteInfoHeader = document.getElementById("trQuoteInfoHeader" + i)
strShowQuoteInfoHeader.style.display = (strShowQuoteInfoHeader.style.display && strShowQuoteInfoHeader.style.display=='block' ? 'none' : 'block');

for(r=0; r<intCountOfQuotes; ++r)
{
document.getElementById("trQuoteInfoDetails" + r).style.display = strShowQuoteInfoHeader.style.display;
}
return true;
}[/CODE]
Copy linkTweet thisAlerts:
@dzirkelbauthorFeb 09.2009 — I tweaked that a bit, and it doesnt' work. I then realized I need to got a little more in depth as there will be multiple id's of trQuoteInfoDetails+r, so I made the individual. Please convert this select case statement into javascript and I'll test that:

<i>
</i>function ShowQuoteInfo(i, intCountOfQuotes, strSection)
{
var strShowQuoteInfoHeader = document.getElementById("trQuoteInfoHeader" + i)
strShowQuoteInfoHeader.style.display = (strShowQuoteInfoHeader.style.display &amp;&amp; strShowQuoteInfoHeader.style.display=='block' ? 'none' : 'block');

<i> </i>select case strSection
<i> </i>case "~"
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i>case "~~"
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails~~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i>case "~~~"
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails~~~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i>case "~~~~"
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails"~~~~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i>end select
}
Copy linkTweet thisAlerts:
@MrNobodyFeb 09.2009 — [CODE]switch (strSection)
{
case "~":
...etc...
break;
case "~~":
...etc...
break;
case "~~~":
...etc...
break;
case "~~~~":
...etc...
break;
default:
alert("Unknown option.");
return false;
}[/CODE]
Copy linkTweet thisAlerts:
@dzirkelbauthorFeb 11.2009 — Thanks for the reply. Here is my javascript function now:

<i>
</i>function ShowQuoteInfo(i, intCountOfQuotes, strSection)
{
var strShowQuoteInfoHeader = document.getElementById("trQuoteInfoHeader" + i)
strShowQuoteInfoHeader.style.display = (strShowQuoteInfoHeader.style.display &amp;&amp; strShowQuoteInfoHeader.style.display=='block' ? 'none' : 'block');


<i> </i>switch (strSection)
<i> </i>{
<i> </i> case "~":
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i> break;
<i> </i> case "~~":
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails~~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i> break;
<i> </i> case "~~~":
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails~~~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i> break;
<i> </i> case "~~~~":
<i> </i> for(r=0; r&lt;intCountOfQuotes; ++r)
<i> </i> {
<i> </i> var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails"~~~~" + r)
<i> </i> strShowQuoteInfoDetails.style.display = (strShowQuoteInfoDetails.style.display &amp;&amp; strShowQuoteInfoDetails.style.display=='block' ? 'none' : 'block');
<i> </i> }
<i> </i> break;
<i> </i> default:
<i> </i> alert("Unknown option.");
<i> </i> return false;
<i> </i>}
}


Upon page load, i get a javascript error...syntax error expecting an ). What did I do wrong?
Copy linkTweet thisAlerts:
@MrNobodyFeb 11.2009 — This line is wrong:
[CODE]var strShowQuoteInfoDetails = document.getElementById("trQuoteInfoDetails"~~~~" + r)[/CODE]
Extra quote.
Copy linkTweet thisAlerts:
@dzirkelbauthorFeb 11.2009 — Thanks for that find, that was a typo.

Now it just comes up with syntax error line 336, and another one for line 503
Copy linkTweet thisAlerts:
@MrNobodyFeb 11.2009 — Can't help you there -- unless you have a live link to the page on your servers.
Copy linkTweet thisAlerts:
@dzirkelbauthorFeb 11.2009 — I found the error, on my button I had "~" instead of '~'. That fixed that problem. now, when I click the button, I get an object expected error. I am going troubleshoot this for a bit tomorrow as I think I am off on my loops with teh startin value or somethin similar (header shows correctly, details does not show and I get teh error).

So, I will post tomorrow sometime probably with either a question or a solution. Thanks for your assistance.
Copy linkTweet thisAlerts:
@dzirkelbauthorFeb 12.2009 — Everything works out great, thanks! The error I had is because my tr loop started at one and my javascript function was starting at 0...thanks for all your help, it looks great!
×

Success!

Help @dzirkelb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...