|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
The Task:
There are certain HTML tags you want to make certain are on a web page. A javascript is used to search for those tags, both opening and closing (such as <H1> and </H1>). These would be created in an array. If all tags are found, it writes to one textarea saying "All needed tags are present". If any are missing, it writes to a 2nd textarea reporting those that were not found in the array. Third (optional), the program would indicate all tags that were not in the array, but were present none-the-less. The web page being analyzed could preferably, have its HTML copied and pasted into a textarea. A mock-up of the form to copy and paste the HTML to be analyzed can be found here: URL However....I get the error: Line 44 Char 1 Error: tagsFound is null or not an object Code: 0 Sigh...I thought I had definded that tag too. Can someone please help, I am at a loss ![]() Anyway, here is the code: -- Code:
<html>
<head>
<script language="javascript">
var myTags =
[
/<html>/i,
/<head>/i,
/<title>/i,
/<body .*>/i,
/<form .*>/i,
/<.*text=.*>/i,
/<.*link=.*>/i,
/vlink=.*>/i,
/<p>/i,
/<br>/i,
/<a.*>/i,
/<.*align=.*>/i,
/<font.*>/i,
/width=.*>/i,
/<.*size=.*>/i,
/<h1/i,
/<h2/i,
/<h4>/i,
/<ol>/i,
/<li>/i,
/<h3.*>/i,
/<ul>/i,
/<b>/i,
/<i>/i,
/<.*href=.*>/i,
/<.*#.*>/i,
/<a.*name=.*>/i
]
;
function checkTags()
{
var htmlText=document.validateForm.html.value;
missing=0;
tagsFound=document.forms[0].tagsFound;
tagsMissing=document.forms[0].tagsMissing;
for(i=0;i<myTags.length;i++)
if(myTags[i].test(htmlText))
tagsFound.value+=myTags[i]+'\n';
else
{
tagsMissing.value+=myTags[i]+'\n';
missing++
}
if(missing==0)
document.forms[0].tagResult.value="All tags found.";
tagsMissing.value=tagsMissing.value.replace(/\/i$/gm,'')
tagsMissing.value=tagsMissing.value.replace(/\/|\\/gm,'')
tagsFound.value=tagsFound.value.replace(/\/i$/gm,'')
tagsFound.value=tagsFound.value.replace(/\/|\\/gm,'')
}
</script>
</head>
<body >
<table width="53%" border="0" cellpadding="10" name="TimeTable" align="center">
<tr>
<td BGCOLOR="#EEEEEE">
Paste your HTML into the text area below, then click
the "Validate HTML" button to insure that the html contains
all of the required tags.
</td>
</tr>
<tr>
<td>
<form name="validateForm" >
<textarea cols=80 rows=10 name="html"></textarea><br>
<input type="BUTTON" name="validate" value="Validate HTML" onClick="checkTags();">
</form>
</td>
</tr>
</table>
<form>
<input type=text name=tagResult>
<p>
Missing:<br>
<textarea name=tagsMissing rows=7 cols=20>
</textArea>
<p>
Found:<br>
<textarea name=tagsFound rows=7 cols=20>
</textArea>
</form>
</body>
</html>
|
|
#2
|
|||
|
|||
|
is this where your js file is??
http://www.california.com/~rshrum/regExprTest.js And use CODE TAGS!!! ie [ code]Some code here[ /code] without the spaces in the actual square braket tags, will give you Code:
Some code here Back to the problem at hand. You aren't retrieving the form text boxs properly. I would recomend you use the DOM to get objects. ie document.getElementById("inputText"); and give everything an "id" attribute. This then means you need to use differnet variable's to your id, just do it. so this works, kind of, think you need to tweak your logic. Code:
<html>
<head>
<script language="javascript">
var myTags = new Array(/<html>/i,
/<head>/i,
/<title>/i,
/<body .*>/i,
/<form .*>/i,
/<.*text=.*>/i,
/<.*link=.*>/i,
/vlink=.*>/i,
/<p>/i,
/<br>/i,
/<a.*>/i,
/<.*align=.*>/i,
/<font.*>/i,
/width=.*>/i,
/<.*size=.*>/i,
/<h1/i,
/<h2/i,
/<h4>/i,
/<ol>/i,
/<li>/i,
/<h3.*>/i,
/<ul>/i,
/<b>/i,
/<i>/i,
/<.*href=.*>/i,
/<.*#.*>/i,
/<a.*name=.*>/i);
function checkTags() {
var missing, htmlText, tagsFound, tagsMissing, tagResult;
missing = 0;
htmlText = document.getElementById("htmlTextIn").value;
tagsMissing = document.getElementById("tagsMissingOut");
tagsFound = document.getElementById("tagsFoundOut");
tagResult = document.getElementById("tagResultOut");
tagsMissing.value = "";
tagsFound.value = "";
tagResult.value = "";
for(i = 0; i < myTags.length; i++) {
if(myTags[i].test(htmlText)) {
tagsFound.value += myTags[i] + '\n';
} else {
tagsMissing.value += myTags[i] + '\n';
missing++
}
}
if(missing == 0) {
tagResult.value = "All tags found.";
}
tagsMissing.value = tagsMissing.value.replace(/\/i$/gm,'')
tagsMissing.value = tagsMissing.value.replace(/\/|\\/gm,'')
tagsFound.value = tagsFound.value.replace(/\/i$/gm,'')
tagsFound.value = tagsFound.value.replace(/\/|\\/gm,'')
}
</script>
</head>
<body>
<table width="53%" border="0" cellpadding="10" name="TimeTable" align="center">
<tr>
<td bgcolor="#EEEEEE">Paste your HTML into the text area below, then click the "Validate HTML" button
to insure that the html contains all of the required tags.</td>
</tr>
<tr>
<td>
<form name="validateForm">
<textarea cols="80" rows="10" name="htmlTextIn" id="htmlTextIn"></textarea>
<br>
<input type="BUTTON" name="validate" value="Validate HTML" onclick="checkTags();">
</form>
</td>
</tr>
</table>
<form>
<input type="text" name="tagResultOut" id="tagResultOut">
<p>Missing:
<br>
<textarea name="tagsMissingOut" rows="7" cols="20" id="tagsMissingOut"></textarea>
<p>Found:
<br>
<textarea name="tagsFoundOut" rows="7" cols="20" id="tagsFoundOut"></textarea>
</form>
</body>
</html>
So to recap the problem you were having was in relation to actually retieveing the objects on the page. I don't like using document.forms[]. whatever takes more time to figure out if your in the right place or not. Just use DOM way of doing things of course if u were making a calculator (or something that had lots of buttonds) maybe it would make sense to use document.forms but this time I reckon the using DOM is betterLast edited by Nigorr : February 23rd, 2003 at 07:02 PM. |
|
#3
|
|||
|
|||
|
Code:
for(i=0;i<myTags.length;i++) if(myTags[i].test(htmlText)) here this is the issue don't forget myTags.length does not equal the times you want to loop. myTags[0] is not accounted for.. you need to loop myTags.length -1 .. so when it looks for the last item in the array it's not there. = Error: tagsFound is null or not an object LOL i did not realize this was posted in 03! saw it on a search - thought i would answer.. ![]() |
|
#4
|
|||
|
|||
|
Quote:
Finally! Now I can turn in this #$%&@ assignment! lol! Thanks, Rick ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > ERROR: Null or not an object (reg exp task) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|