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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation Error....I'm stumped.... 2

Status
Not open for further replies.

Dorff

Programmer
Mar 13, 2002
72
CA
I get this error on line 36 which I marked below. The field names are fine and so is the logic I believe. I can't see the error. Any ideas?

<script type=&quot;text/javascript&quot;>
<!--
function validate()
{
x=document.myForm
column1=x.column.value
testValue=x.testValue.value
validDate=x.searchDate.value
groupedDate=x.groupedDate.value
groupedYear=x.groupedYear.value
fromDate=x.fromDate.value
toDate=x.toDate.Value

submitOK=&quot;True&quot;

if (groupedDate != &quot;NONE&quot; && validDate != &quot;&quot; || groupedYear != &quot;&quot; && validDate != &quot;&quot;)
{
alert(&quot;You cannot search for a specific date\nAND a grouped period at the same time.&quot;)
submitOK=&quot;False&quot;
}

if (toDate != &quot;&quot; && groupedDate != &quot;&quot; || fromDate != &quot;&quot; && groupedDate != &quot;&quot; || toDate != &quot;&quot; && groupedYear != &quot;&quot; || fromDate != &quot;&quot; && groupedYear != &quot;&quot;)
{
alert(&quot;You cannot specify a date range\nAND a grouped period at the same time.&quot;)
submitOK=&quot;False&quot;
}

if (toDate != &quot;&quot; && validDate != &quot;&quot; || fromDate != &quot;&quot; && validDate != &quot;&quot;)
{
alert(&quot;You cannot search for a specific date\nAND a date range at the same time.&quot;)
submitOK=&quot;False&quot;
}

if (fromDate.length != 0 && toDate = &quot;&quot;)
{
alert(&quot;To use the date range, you must\nenter two proper dates.&quot;)
submitOK=&quot;False&quot;
}

if (fromDate.length = 0 && toDate.length != 0)
{
alert(&quot;To use the date range, you must\nenter two proper dates.&quot;)
submitOK=&quot;False&quot;
}


if (groupedDate = &quot;NONE&quot;)
{
if (groupedYear.length != 0 && groupedYear.length < 4)
{
alert(&quot;When reporting by year, year field must be 4 characters.\n Ex. 2002 not 02&quot;)
submitOK=&quot;False&quot;
}
}

if (column1 != &quot;Identifier&quot;)
{
if (!testValue)
{
alert(&quot;Invalid Test Value for Search Criteria.\n\nField cannot be left empty.&quot;)
submitOK=&quot;False&quot;
}
}

if (fromDate.length > 0 && fromDate.length != 8)
{
alert(&quot;Invalid From Date Entry. Date must be in MM/DD/YY format.&quot;)
submitOK=&quot;False&quot;
}

if (toDate.length > 0 && toDate.length != 8)
{
alert(&quot;Invalid To Date Entry. Date must be in MM/DD/YY format.&quot;)
submitOK=&quot;False&quot;
}

if (validDate.length > 0)
{
if (validDate.length != 8)
{
alert(&quot;Invalid Date Entry. Date must be in MM/DD/YY format.&quot;)
submitOK=&quot;False&quot;
}
}
if (submitOK==&quot;False&quot;)
{
return false
}
}

Thanks in advance.
Ryan
rmindorff@hotmail.com
 
Sorry, the error is simply a runtime error on Line 36. Ryan
rmindorff@hotmail.com
 
may I recommend something to clean up your code and make it more readable :

x=document.myForm
column1=x.column.value
testValue=x.testValue.value
validDate=x.searchDate.value
groupedDate=x.groupedDate.value
groupedYear=x.groupedYear.value
fromDate=x.fromDate.value
toDate=x.toDate.Value

change to :

with (document.myForm)
{
var column1 = colum.value
//etc...
}

Also inside a function if you plan to use variable only within the scope of your function you should specify var before the variable name. That way you do not have mixups.

Try that to see if it might fix some problems.

Hope this helps. Gary Haran
 
when checking a comparison is javascript you need to use == instead of =
So
toDate = &quot;&quot;
should be toDate==&quot;&quot;
I also noticed that problem in other places
fromDate.length = 0
groupedDate = &quot;NONE&quot;
 
Thank you very much, I took both pieces of advice and now have an easy to read/working version. Thanks again. Ryan
rmindorff@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top