Accurately Count Elements
Hi all,
I have designed a small and limited client-side forum. It works by dumping textfiles into a directory and then displaying the content using innerHTML which is read from a hidden field on a results page. You can also reply to it using append, and inputting the ID of the message. Now what I want to be able to do is count how many replies there are per topic. I have tried a simple counting loop with indexOf and searching for the string "<table " as I am using simple tables to display the content in each post. I just can't seem to accurately count the replies. So what I am looking for is to accurately count tables within the page. I am using a hidden field to grab the contents of textfiles, then using this string with innerHTML to populate divs. Here is the code:
This is the containing page with an iframe:
<html>
<head><link rel ="stylesheet" type ="text/css" href ="P:\clevedon staff\training program\training pack\bodystyle2.css">
<title>
CCF WebForum - Have your say!
</title>
</head>
<body bgcolor ="#FFDAB9" onload ="retrievepinstimeout()">
<table width = "100%" cellpadding =0 cellspacing =0 border ="1" bordercolor ="black" background ="P:\clevedon staff\training program\training pack\bgcolor2.gif"><tr><td><b>.CCF WebForum</td></tr></table> <b>.Menu</b>
<div id ="menudiv" style ="position:absolute; overflow:auto; width:100%; height:25; border:1px solid black; background-image:url(P:\clevedon staff\training program\training pack\bgcolor2.gif); top:40; left:2"><a href="post.htm" target ="contentframe">.Post</a> | <a href ="search.htm" target ="contentframe">.Search</a> | <a href ="mailto:joe.foster@comet.co.uk">.Contact Designer</a> | <a href ="file:\\\P:\clevedon staff\training program\training pack\page1.htm">.InfoCentre</a></div>
<center>
<div align ="center" id ="iframediv" style ="position:absolute; width:100%; height:640; border:1px solid black; background-image:url(P:\clevedon staff\training program\training pack\ewsbgr10.jpg); top:90; left:2"><center><iframe name ="contentframe" src ="post.htm" height =398 width =96%></iframe></center></div>
<div id ="getpinsdiv" style ="position:absolute; top:200; right:240; border: 1px solid black; background-image:url(P:\clevedon staff\training program\training pack\bgcolor2.gif)"><b>Current Pins Open:</b></div>
<div id = "pincontainer" style ="position:absolute; height:70; width:124; top:222; right:240; border: 1px solid black; visibility:hidden; color:black; overflow:auto"></div>
</center>
<script language ="javascript">
function retrievepinstimeout(){
setInterval("retrievepins()", 20)
}
</script>
<script language ="vbscript">
sub retrievepins()
On Error Resume Next
dim fs, rf, cont
set fs = CreateObject("Scripting.FileSystemObject")
set rf = fs.OpenTextFile("P:\\clevedon staff\\training program\\training pack\\ccf\\pinupdates.txt", 1, false)
cont = rf.Read(10000000)
document.hiddenform.hidden1.value = cont
rf.close
updatepincontainer()
end sub
</script>
<script language ="javascript">
function updatepincontainer(){
pincontainer.style.visibility ="visible";
pincontainer.innerHTML = document.hiddenform.hidden1.value + "<br>"
}
</script>
<form name ="hiddenform">
<input type ="hidden" name ="hidden1">
</form>
</body>
</html>
Then I have the iframe to navigate, this is the post page:
<html>
<head><link rel ="stylesheet" type ="text/css" href ="P:\clevedon staff\training program\training pack\bodystyle2.css">
<title>
CCF WebForum Post Form)
</title>
</head>
<body>
<table width = "100%" cellpadding =0 cellspacing =0 border ="1" bordercolor ="black" background ="P:\clevedon staff\training program\training pack\bgcolor2.gif"><tr><td><b>.CCF WebForum Post Form</td></tr></table>
Post all your requests here. Your CCF representative will reply to your post as soon as possible. Please remember that personal issues should be addressed directly to your line management. However please also note that this forum is strictly confidential and nothing you say will be traced back to you in any way. Remember to take note of the pin number in the box on the right below. You will need this and the date to recover any posts in the future.<br>
<div id ="postdiv" style ="position:absolute; top:90; left:2; height:300; width:98%; border:1px solid black; background-color:ffffcc"><form name = "form1">Nickname:<br><input type ="text" size = 10 maxlength =10 name ="text1"><br>Date (DDMMYY):<br><input type ="text" name ="text2" maxlength ="6" size ="6"><br>Details:<br><textarea name ="text3" rows ="10" cols ="50"></textarea><br><button name ="postthedetails" onclick ="postdetails()" style ="height:23; background-image:url(P:\clevedon staff\training program\training pack\bgcolor2.gif);"><b>.Post</b></button></form></div>
<div id ="pindiv" style = "position:absolute; top:106 ; right:36; height:20; width:60; border: 1px solid black; background-image:url(P:\clevedon staff\training program\training pack\tecbkgnd.gif)"></div>
<script language ="javascript">
for(pincount =0; pincount < 100; pincount++)
{
pinnumber = (Math.floor(Math.random()*100000)+1);
document.getElementById("pindiv").innerHTML = "<center>" + pinnumber + "<\/font><\/center>";
}
function postdetails(){
var agtname = document.form1.text1.value;
var thedate = document.form1.text2.value;
var thecontent = document.form1.text3.value;
var txtfile = "P:\\clevedon staff\\training program\\training pack\\ccf\\" + pinnumber + " " + thedate + ".txt"
var TristateFalse =0;
var ForAppending =8;
var noOfLines =0;
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
myActiveXObject.CreateTextFile(txtfile);
file = myActiveXObject.GetFile(txtfile);
text = file.OpenAsTextStream(ForAppending, TristateFalse);
text.Write("<div align=\"left\"><table background = \"P:\\clevedon staff\\training program\\training pack\\bgcolor2.gif\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"24%\"><tr><td width=\"100%\">Name: <\/font>" + "" + agtname + "<\/font><\/td><\/tr><\/table><\/div><div align=\"left\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"24%\"><tr><td width=\"100%\"><b>Date:<\/b><\/font> " +"" + thedate + "<\/font><\/td><\/tr><\/table><\/div><div align=\"left\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"5%\" height=\"11\"><tr><td width=\"100%\" height=\"11\"><b>Details:<\/b> " + "<\/font><\/td><\/tr><\/table><\/div>" + thecontent + "<br>")
//is there any need to escape characters within the text.Write method?
text.Close()
updatepinfile()
}
function updatepinfile(){
var pintext ="P:\\clevedon staff\\training program\\training pack\\ccf\\pinupdates.txt"
//this displays available messages by date and unique pin
var TristateFalse =0;
var ForAppending =8;
var noOfLines =0;
var thedate2 = document.form1.text2.value;
mXO2 = new ActiveXObject("Scripting.FileSystemObject");
file2 = mXO2.GetFile(pintext);
text2 = file2.OpenAsTextStream(ForAppending, TristateFalse);
text2.Write("" + pinnumber + " " + thedate2 + "<\/font>" + " | " + "<br>")
text2.Close()
document.forms[0].reset
document.write("Your post has been successful. Please navigate to the search page to retrieve it.")
}
</script>
<div id ="cantpost" style ="position:absolute; right:46; bottom:20; width:200; border:1px solid black">Can't post? Click <a href ="mailto:me@domain.co.uk">here</a> to contact the forum moderator.</div>
</body>
</html>
Then this is the retrieval and reply page where I want to count replies:
<html>
<head><link rel ="stylesheet" type ="text/css" href ="P:\clevedon staff\training program\training pack\bodystyle2.css">
<title>
CCF WebForum (Post Form)
</title>
</head>
<body>
<table width = "100%" cellpadding =0 cellspacing =0 border ="1" bordercolor ="black" background ="P:\clevedon staff\training program\training pack\bgcolor2.gif"><tr><td><b>.CCF WebForum DateSearch</td></tr></table>
Search for webforum updates from here. Remember that the date format you should search in is: DDMMYY, with no gaps or any form of punctuation.<br><br>
<form name ="search">
.Date:<br>
<input type ="text" size =6 maxlength =6 name ="datefield"><br>
.PIN:<br>
<input type = "text" name ="pin"><br>
<button name ="confirmdate" style ="height:23;background-image:url(P:\clevedon staff\training program\training pack\bgcolor2.gif)" onclick ="retrievepost()"><B>.Go</b></button>
</form>
<div id ="div1" style ="position:absolute; top:230; left:0; border:1px solid black; visibility:hidden"></div>
<div id = "howmanyreplies" style ="position:absolute; top:180"></div>
<script language ="javascript">
function retrieve(){
div1.style.visibility ="visible";
div1.innerHTML ="<b>Sorry, there are no posts available. Please try a different date.<\/b>"
}
</script>
<script language ="vbscript">
sub retrievepost()
On Error Resume Next
dim fs, rf, cont
set fs = CreateObject("Scripting.FileSystemObject")
set rf = fs.OpenTextFile("P:\\clevedon staff\\training program\\training pack\\ccf\\" + document.search.pin.value + " " + document.search.datefield.value + ".txt", 1, false)
cont = rf.Read(10000000)
document.hiddenform.hidden1.value = cont
rf.close
updatediv1()
end sub
</script>
<script language ="javascript">
//var foundat = 0;
//var tablecount =0;
//function updatereplies(){
//var counttables = document.hiddenform.hidden1.value
//var tableval = "url"
//while (foundat !=-1){
//foundat = counttables.indexOf(tableval, foundat);
//if (foundat !=-1){
//tablecount++
//foundat++
//}
//alert(tablecount)
//}
//howmanyreplies.innerText = (tablecount-1)
//}
</script>
<form name ="hiddenform">
<input type ="hidden" name ="hidden1">
<input type ="hidden" name ="hidden2">
</form>
<script language ="javascript">
function updatediv1(){
div1.style.visibility ="visible";
div1.innerHTML = document.hiddenform.hidden1.value
}
</script>
<div id ="replydiv" style ="position:absolute; top:40; right:16; height:20; width:200; border:1px solid black; background-image:url(P:\clevedon staff\training program\training pack\bgcolor2.gif)"><center><b>.Reply</b></center></div>
<div id ="replydiv2" style ="position:absolute; top:60; right:16; height:150; width:200; border:1px solid black;overflow:auto;"><form name ="replyform">Name:<br><Input type ="text" name ="textname"><br>Details:<br><textarea name ="textdetails" rows = 5 cols = 18></textarea><br><button name ="sub" onclick ="reply1()" style ="height:23; background-image:url(P:\clevedon staff\training program\training pack\bgcolor2.gif)"><b>.Reply</b></button></div>
<script language ="javascript">
function reply1(){
if (document.hiddenform.hidden1.value ==""){
alert("There are no active topics on the board at the moment. Please retrieve a topic before attempting to reply!")}
else{
var TristateFalse =0
var ForAppending =8
var noOfLines=0
var thefilenameb = "P:\\clevedon staff\\training program\\training pack\\ccf\\" + document.search.pin.value +" " + document.search.datefield.value + ".txt"
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
file = myActiveXObject.GetFile(thefilenameb);
text = file.OpenAsTextStream(ForAppending, TristateFalse);
text.Write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td width=\"100%\" valign =\"center\">Name: " + document.replyform.textname.value + "<\/font><\/td><\/tr><\/table><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"90%\" height=\"11\"><tr><td width=\"100%\" height=\"11\">Details:<br>" + document.replyform.textdetails.value + "<\/font><\/td><\/tr><\/table><br>")
text.Close();
document.forms[2].reset()
//updatereplies()
setInterval("retrievepost()",20);
setInterval("updatediv1()", 20);
}
}
</script>
</body>
</html>
Any help much appreciated.
TIA
interrupt
__________________
\'sync\' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
|