I have a function as below:
function onStartValidation()
{
//For DIV
#indivcount=0;
$divclassarray='';
//For P
#inptagcount=0;
$ptagclassarray='';
}
function onStartTag_div()
{
#indivcount++;
if hasAtt("class")
{
#classindex=getAttIndex("class");
$classvalue=getAttValue(#classindex);
//Methods for DIV
$divclassarray[#indivcount]=$classvalue;
}
function onEndTag_div()
{
$divclassarray[#indivcount]='';
#indivcount--;
}
function onStartTag_p()
{
#inptagcount++;
If hasAtt(“class”)
{
#ptagclassindex=getAttIndex("class");
$ptagclassvalue=getAttValue(#ptagclassindex);
//Methods when <p> has a class
}
else
{
//throw error is <p> tag not inside <div class="abc">
If isValueInArray("divclassarray","abc")<0
{
Message(1,MSG_ERROR,'Text inside <div class="abc" should be inside a <p> tag.');
}
}
function onEndTag_p()
{
$ptagclassarray[#inptagcount]='';
#inptagcount--;
}
The problem I am having with the above code is that if <div class="abc"> is not present in my HTML (and thus not in divclassarray) - it throws error for every <p> tag on the page. However, if there is a <div class="abc"> and the text inside it is not within a <p> tag - I expected the error to be thrown but it did not
I tried modifying the above line to include matchCase("divclassarray","abc") and beginsWithCase("abc","divclassarray")>1 to check whether <div class="abc"> is present or not and then do isValueInArray - but this does not help either.
Basically, what I want to do is check if <p> tag is present inside <div class="abc">, if <div class="abc"> exists.
Hope this makes sense.
Thanks in advance!
-Anjana P



