Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

showhide dynamic table rows

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
i know this a jscript q - but have a nice function
that show/hides table rows, the problem is because
this is a dynamic table populated from db.

this is a list of makes in stock with respective models listed beneath. i want the model rows to be hidden until a user clicks 'show' button and then the models are displayed.

at the moment the code only works with the first make in the list. i am surprised that all the rows in the table dont show/hide.

let me know if im talking rubbish and i will try to explain better. also i dont think i need two loops for this so it is a messy way of ding this.

Code:
 <script language="javascript" type="text/javascript">
   function FuncShowHide(){
      
      if (document.getElementById('hideShow').style.display == document.getElementById('trX').style.display){
         document.getElementById('hideShow').style.display = "none";
      } else {
         document.getElementById('hideShow').style.display = document.getElementById('trX').style.display
      }
   }
</script>

modsql = "SELECT count(stock.model) AS modcount, stock.model, stock.make "_
& "FROM stock "_
& "GROUP BY model "_
& "ORDER BY model"

countsql = "SELECT count(stock.make) AS makecount, stock.make AS makeid, make.make AS makequick "_
& "FROM stock "_
& "INNER JOIN make on make.makeid = stock.make "_
& "GROUP BY makeid"

Set rsmakecount = Server.CreateObject("ADODB.Recordset")
rsmakecount.Open countsql, conn

response.Write("<table border=0 cellspacing=0 cellpadding=2>")
x_makecount=0

 Do While (Not rsmakecount.Eof) 
x_makeid = rsmakecount("makeid")
x_makequick = rsmakecount("makequick")
x_makecount = rsmakecount("makecount")

response.Write "<tr id=trX><td colspan=2><a href=3coltemp.asp?pagesetupid=2&x_Make=" & Server.URLEncode(x_makeid) & "&z_Make==,','><span class=quickfindlge>" & (x_makequick) & "</span></a></td><td><input name=showhide type=image onClick=FuncShowHide();chgimg(this);return false; src=images/showbut2.gif width=13 height=9></td><td><span class=quickfindlge>("& (x_makecount) & ")</span></td></tr>"

reccount=0

rsmod.Open modsql, conn
totrecs = rsmod.RecordCount
startrec = 1
lastrec = totrecs

Do While (Not rsmod.Eof)
reccount=reccount+1
if rsmod("make") = x_makeid then
x_modcount = rsmod("modcount")
x_mod = rsmod("model")
response.Write "<tr id=""hideshow"" style=""display: none;""><td><img src=images/spacer.gif width=5></td><td><a href=3coltemp.asp?pagesetupid=2&x_Model=" & Server.URLEncode(x_mod) & "&z_Model==,','&x_Make=" & Server.URLEncode(x_makeid) & "&z_Make==,','><span class=quickfind>" & (x_mod) & "</span></a></td><td></td><td><span class=quickfind>("& (x_modcount) & ")</span></td></tr>"
end if
rsmod.MoveNext
Loop

if reccount = lastrec then
rsmod.movefirst
end if

'end if
rsmakecount.MoveNext
Loop

rsmakecount.close
conn.Close
Set conn = Nothing

response.Write("</table>")
 
I find it easier to debug client-side javascript if I separate it from the ASP.

I prefer to load the page, click "View Source" in the browser, and then save the source off as a separate HTML file.

Then I can debug the HTML file and focus only on the client-side script.

Once I get this working as intended, I work backward to integrate the client-side code back into my ASP.
 
just a tip for making show/hide functions easier also

call them with showhide(this)

then
function showhide(object this)

then you have a direct handle on the single item to show/hide rather than getting elementbyname
 
oops sorry

function showhide(obj)
{
if (obj.style.display...

is what i meant (x-language confusion :) )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top