JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 23rd, 2003, 07:48 AM
rik408 rik408 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 rik408 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 24 sec
Reputation Power: 0
Unhappy ERROR: Null or not an object (reg exp task)

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>

Reply With Quote
  #2  
Old February 23rd, 2003, 05:29 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
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 better

Last edited by Nigorr : February 23rd, 2003 at 06:02 PM.

Reply With Quote
  #3  
Old May 12th, 2007, 05:57 AM
blitz01 blitz01 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 7 blitz01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 19 m 52 sec
Reputation Power: 0
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..

Reply With Quote
  #4  
Old May 13th, 2007, 08:34 AM
rik408 rik408 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 rik408 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 24 sec
Reputation Power: 0
Quote:
Originally Posted by blitz01
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..


Finally!
Now I can turn in this #$%&@ assignment!
lol!

Thanks,
Rick

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > ERROR: Null or not an object (reg exp task)


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap