close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Validation no longer working...old version though. :(

Thread began 10/31/2014 11:36 am by Nathon Jones Web Design | Last modified 11/06/2014 1:33 pm by Jason Byrnes | 1443 views | 22 replies |

Nathon Jones Web Design

Validation no longer working...old version though. :(

The form validation on an old form has stopped working. It's an old classic ASP website though so I can't use the extension anymore on it but I wondered if you could spot anything obvious...

Here is the form tag info:

<form action="music-events-search.asp" method="post" name="eventsearchform" id="eventsearchform" onsubmit="WAValidateRQ(document.forms[0].sdate,'- Please enter a start date.',document.forms[0].sdate,0,false,'text');WAValidateRQ(document.forms[0].edate,'- Please enter an end date.',document.forms[0].edate,0,false,'text');WAValidateDT(document.forms[0].sdate,'- Invalid date.',true,/.*/,'','','',false,/.*/,'','','',document.forms[0].sdate,0,false);WAValidateDT(document.forms[0].edate,'- Invalid date.',true,/.*/,'','','',false,/.*/,'','','',document.forms[0].edate,0,false);WAValidateRT(document.forms[0].k,document.forms[0].k.value,'- Invalid content in your keyword search.','%7B|%7B, %7D|%7D, %5B|%5B, %5D|%5D, //|//, :|:, ;|;, (|(, )|), =|=, +|+, _|_, http|http, http|http, %5Burl|%5Burl, /url%5D|/url%5D, %25|%25, $|$, #|#, %5Blink|%5Blink, /link%5D|/link%5D',document.forms[0].k,0,false);WAAlertErrors('The following errors were found','Correct invalid entries to continue',true,false,false);return document.MM_returnValue">

And here is the client validation code:
<script type="text/JavaScript">
<!--
function WAtrimIt(theString,leaveLeft,leaveRight) {
if (!leaveLeft) {
while (theString.charAt(0) == " ")
theString = theString.substring(1);
}
if (!leaveRight) {
while (theString.charAt(theString.length-1) == " ")
theString = theString.substring(0,theString.length-1);
}
return theString;
}

function WAFV_GetValueFromInputType(formElement,inputType,trimWhite) {
var value="";
if (inputType == "select") {
if (formElement.selectedIndex != -1 && formElement.options[formElement.selectedIndex].value && formElement.options[formElement.selectedIndex].value != "") {
value = formElement.options[formElement.selectedIndex].value;
}
}
else if (inputType == "checkbox") {
if (formElement.length) {
for (var x=0; x<formElement.length ; x++) {
if (formElement[x].checked && formElement[x].value!="") {
value = formElement[x].value;
break;
}
}
}
else if (formElement.checked)
value = formElement.value;
}
else if (inputType == "radio") {
if (formElement.length) {
for (var x=0; x<formElement.length; x++) {
if (formElement[x].checked && formElement[x].value!="") {
value = formElement[x].value;
break;
}
}
}
else if (formElement.checked)
value = formElement.value;
}
else if (inputType == "radiogroup") {
for (var x=0; x<formElement.length; x++) {
if (formElement[x].checked && formElement[x].value!="") {
value = formElement[x].value;
break;
}
}
}
else if (inputType == "iRite") {
var theEditor = FCKeditorAPI.GetInstance(formElement.name) ;
value = theEditor.GetXHTML(true);
}
else {
var value = formElement.value;
value=value.replace(/<p>(\&\#160\;)*<\/p>/,"");
}
if (trimWhite) {
value = WAtrimIt(value);
}
return value;
}

function WAAddError(formElement,errorMsg,focusIt,stopIt) {
if (document.WAFV_Error) {
document.WAFV_Error += "\n" + errorMsg;
}
else {
document.WAFV_Error = errorMsg;
}
if (!document.WAFV_InvalidArray) {
document.WAFV_InvalidArray = new Array();
}
document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
if (focusIt && !document.WAFV_Focus) {
document.WAFV_Focus = focusIt;
}

if (stopIt == 1) {
document.WAFV_Stop = true;
}
else if (stopIt == 2) {
formElement.WAFV_Continue = true;
}
else if (stopIt == 3) {
formElement.WAFV_Stop = true;
formElement.WAFV_Continue = false;
}
}

function WAValidateRQ(formElement,errorMsg,focusIt,stopIt,trimWhite,inputType) {
var isValid = true;
if (formElement.length && inputType.toLowerCase()!="radio" && inputType.toLowerCase()!="select") formElement=formElement[0];
if (!document.WAFV_Stop && !formElement.WAFV_Stop) {
var value=WAFV_GetValueFromInputType(formElement,inputType,trimWhite);
if (value == "") {
isValid = false;
}
}
if (!isValid) {
WAAddError(formElement,errorMsg,focusIt,stopIt);
}
}

function WAGetDateFormat(value, dateFormat) {
var isUSServ = (new Date("1/2/2006").getMonth() == 0);
var tValue = value;
var isEuroDate = ((dateFormat && String(dateFormat).indexOf("[12]\\d|3[0-1]") < String(dateFormat).indexOf("1[0-2]|") && String(dateFormat).indexOf("\\w*") < 0 && (String(dateFormat).indexOf("\\d{4}") < 0 || (String(dateFormat).indexOf("\\d{4}") >= 0 && String(dateFormat).indexOf("\\d{4}") > String(dateFormat).indexOf("[12]\\d|3[0-1]")))) || (!isUSServ));
if ((isEuroDate && isUSServ) || (!isEuroDate && !isUSServ)) {
var datePattn = /(\d*)[-\.\/](\d*)[-\.\/](\d*)/;
var tMatch = tValue.match(datePattn);
if (tMatch && String(tMatch[1]).length != 4) {
if (isEuroDate) {
value = tMatch[2] + "/" + tMatch[1] + "/" + tMatch[3];
}
else {
value = tMatch[1] + "/" + tMatch[2] + "/" + tMatch[3];
}
if (tValue.indexOf(" ") > 0) {
value += tValue.substring(tValue.indexOf(" "));
}
}
}
return new Date(value.replace(/[-\.]/g,"/"));
}

function WADateFormat(format,dateVar) {
var fullYear = dateVar.getYear();
if (fullYear <= 10) fullYear += 2000;
if (fullYear <= 200) fullYear += 1900;
dateVar.setYear(fullYear);
var newDate = format;
var ampm = "A";
var ampmReplace = "p";
var month = dateVar.getMonth() +1;
var monthName = "January";
if (month == 2) monthName="February";
if (month == 3) monthName="March";
if (month == 4) monthName="April";
if (month == 5) monthName="May";
if (month == 6) monthName="June";
if (month == 7) monthName="July";
if (month == 8) monthName="August";
if (month == 9) monthName="September";
if (month == 10) monthName="October";
if (month == 11) monthName="November";
if (month == 12) monthName="December";
var monthNameReplace = "Month";
var monthReplace = "m";
var day = dateVar.getDate();
var dayReplace = "d";
var year = dateVar.getYear();
if (String(year).length > 2)
year = String(year).substring(year.length-2,year.length);
var yearReplace = "yy";
var hour = dateVar.getHours();
var hourReplace = "h";
var minute = dateVar.getMinutes();
if (String(minute).length == 1)
minute = "0" + minute;
var minuteReplace = "nn";
var second = dateVar.getSeconds();
if (String(second).length == 1)
second = "0" + second;
var secondReplace = "ss";
var timeFormat = "";
if (format.indexOf(":")>=0) {
timeFormat = format.substring(format.indexOf(":"));
newDate = format.substring(0,format.indexOf(":"));
timeFormat = newDate.substring(newDate.lastIndexOf(" "))+ timeFormat;
newDate = newDate.substring(0,newDate.lastIndexOf(" "));
}
if (timeFormat.indexOf("h:n")>=0) {
if (timeFormat.indexOf("p")>=0) {
if (hour >= 12) {
ampm = "P"
if (hour>12)
hour = hour -12;
}
if (timeFormat.indexOf("pm")>=0) {
ampm += "M"
ampmReplace = "pm"
}
}
if (timeFormat.indexOf("hh")>=0) {
if (String(hour).length == 1)
hour = "0" + hour;
hourReplace = "hh";
}
timeFormat = timeFormat.replace(hourReplace,hour).replace(minuteReplace,minute).replace(secondReplace,second).replace(ampmReplace,ampm);
}
if (newDate.indexOf("yy")>=0) {
if (newDate.indexOf("yyyy")>=0) {
year = fullYear;
yearReplace = "yyyy";
}
if (newDate.indexOf("mm")>=0) {
if (String(month).length == 1)
month = "0" + month;
monthReplace = "mm";
}
if (newDate.indexOf("dd")>=0) {
if (String(day).length == 1)
day = "0" + day;
dayReplace = "dd";
}
newDate = newDate.replace(yearReplace,year).replace(monthReplace,month).replace(dayReplace,day).replace(monthNameReplace,monthName);
}
return newDate + timeFormat;
}

function WAValidateTheTime(doTime, timeFormat, value, isValid, timeMin, timeMax) {
if (doTime) {
if (timeFormat) {
if (value.search(timeFormat)<0) {
isValid = false;
}
}
if (value.indexOf(":")<0) {
isValid = false;
}
if (isValid) {
var dateVar = new Date(value.replace(/-/g,"/"));
var fullYear = dateVar.getYear();
if (isNaN(dateVar.valueOf()) || (dateVar.valueOf() == 0))
dateVar = new Date("1/1/1 "+value);
if (isNaN(dateVar.valueOf()) || (dateVar.valueOf() == 0))
isValid = false;
if (timeMin != "") {
var Today = new Date(timeMin);
if (isNaN(Today.valueOf()) || Today.valueOf() == 0) {
Today = new Date("1/1/1 "+timeMin);
}
if (isNaN(Today.valueOf()) || Today.valueOf() == 0) {
Today = eval(timeMin);
}
if (dateVar < Today)
isValid = false;
}
if (timeMax != "") {
var Today = new Date(timeMax);
if (isNaN(Today.valueOf()) || Today.valueOf() == 0) {
Today = new Date("1/1/1 "+timeMax);
}
if (isNaN(Today.valueOf()) || Today.valueOf() == 0) {
Today = eval(timeMax);
}
if (dateVar > Today)
isValid = false;
}
}
}
return isValid;
}

function WAValidateDT(formElement,errorMsg,doDate,dateFormat,dateReformat,dateMin,dateMax,doTime,timeFormat,timeReformat,timeMin,timeMax,focusIt,stopIt,required) {
var isValid = true;
var value = formElement.value;
var Now = new Date();
var Today = Now;
Today.setHours(0);
Today.setMinutes(0);
Today.setSeconds(0);
if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value=="")) {
if (doDate) {
if (dateFormat) {
if (value.search(dateFormat)<0) {
isValid = false;
}
}
if (isValid) {
var dateVar = WAGetDateFormat(value, dateFormat);
if (isNaN(dateVar.valueOf()) || (dateVar.valueOf() == 0))
isValid = false;
if (dateMin != "") {
var compareDay = WAGetDateFormat(dateMin, dateFormat);
if (isNaN(compareDay.valueOf()) || compareDay.valueOf() == 0) {
compareDay = eval(dateMin);
}
if (dateVar < compareDay)
isValid = false;
}
if (dateMax != "") {
var compareDay = WAGetDateFormat(dateMax, dateFormat);
if (isNaN(compareDay.valueOf()) || compareDay.valueOf() == 0) {
compareDay = eval(dateMax);
}
if (dateVar > compareDay)
isValid = false;
}
}
}
if (doTime) {
isValid = WAValidateTheTime(doTime, timeFormat, value, isValid, timeMin, timeMax);
}
if (!isValid) {
WAAddError(formElement,errorMsg,focusIt,stopIt);
}
else {
var newVal = "";
if (doDate) {
if (dateReformat!="") {
var newVal = dateReformat;
}
else {
newVal = value;
if (newVal.search(/\s*\d*:/)>0)
newVal = newVal.substring(0,newVal.search(/\s*\d*:/));
}
if (doTime && timeReformat == "" && value.search(/\s*\d*:/)>0) newVal += value.substring(value.search(/\s*\d*:/));
}
else {
dateVar = new Date("1/1/1 " +value);
}
if (doTime) {
if (newVal != "")
newVal += " ";
if (timeReformat!="") {
newVal += timeReformat;
}
else if (!doDate) {
newVal = value;
}
}
formElement.value = WADateFormat(newVal,dateVar);
}
}
}

function WAValidateRT(formElement,value,errorMsg,notAllowed,focusIt,stopIt,required) {
var isValid = true;
var augValue = " " + value + " ";
var tempVal = augValue.toLowerCase();
if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value=="")) {
var notAllowed = notAllowed.split(", ");
for (var x=0; x<notAllowed.length; x++) {
var notAllowedInfo = notAllowed[x].split("|");
notAllowedInfo[0] = unescape(notAllowedInfo[0]);
notAllowedInfo[1] = unescape(notAllowedInfo[1]);
while (tempVal.indexOf(notAllowedInfo[0].toLowerCase())>=0) {
isValid = false;
var theIndex = tempVal.indexOf(notAllowedInfo[0].toLowerCase())
tempVal = tempVal.substring(0,theIndex) + tempVal.substring(theIndex+notAllowedInfo[0].length);
if (notAllowedInfo[1]!="") {
theIndex = augValue.toLowerCase().indexOf(notAllowedInfo[0].toLowerCase())
augValue = augValue.substring(0,theIndex) + notAllowedInfo[1] + augValue.substring(theIndex+notAllowedInfo[0].length);
}
}
}
}
if (required && value=="")
isValid = false;
if (!isValid) {
WAAddError(formElement,errorMsg,focusIt,stopIt);
formElement.value = augValue.substring(1,augValue.length-1);
}
}

function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm,allowOverride) {
if (!document.WAFV_StopAlert) {
document.WAFV_StopAlert = true;
if (document.WAFV_InvalidArray) {
document.WAFV_Stop = true;
var errorMsg = document.WAFV_Error;
if (errorHead!="")
errorMsg = errorHead + "\n" + errorMsg;
if (errorFoot!="")
errorMsg += "\n" + errorFoot;
document.MM_returnValue = false;
if (document.WAFV_Error!="") {
if (allowOverride) {
if (confirm(errorMsg.replace(/&quot;/g,'"'))) {
document.MM_returnValue = true;
return;
}
}
else {
alert(errorMsg.replace(/&quot;/g,'"'));
}
}
else if (submitForm)
submitForm.submit();
if (setFocus && document.WAFV_Focus) {
if (document.getElementById(document.WAFV_Focus.name+"___Config") && document.WAFV_Focus.type.toLowerCase() == "hidden") {
var theEditor = FCKeditorAPI.GetInstance(document.WAFV_Focus.name);
theEditor.EditorWindow.focus();
setTimeout("setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1);
}
else {
document.tempFocus = document.WAFV_Focus;
setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1);
}
}
else {
document.WAFV_Stop = false;
document.WAFV_StopAlert = false;
}
for (var x=0; x<document.WAFV_InvalidArray.length; x++) {
document.WAFV_InvalidArray[x].WAFV_Stop = false;
}
}
else {
document.WAFV_Stop = false;
document.WAFV_StopAlert = false;
if (submitForm) {
submitForm.submit();
}
document.MM_returnValue = true;
}
document.WAFV_Focus = false;
document.WAFV_Error = false;
document.WAFV_InvalidArray = false;
}
}
//-->
</script>

I just need a temporary fix for now, if possible.
Thank you
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

I'll need to troubleshoot directly, see the private message section.

Sign in to reply to this post

Nathon Jones Web Design

http://www.tmsa.org.uk/music-events-search.asp

Thank you Jason.
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

The problem would have started when you added the yahoo search form.

when the validation is created, it uses the form index to refer to the form in the javascript code. when it was created it used index 0 because it was the only form on the page:
document.forms[0].

the yahoo search form has since been added, and it occurs before the events form, so now the yahoo form is index 0 and the events search for is index 1.

in the onchange event for the events search form, change each instance of:
document.forms[0]

to:
document.forms[1].



onsubmit="WAValidateRQ(document.forms[0].sdate,'- Please enter a start date.',document.forms[1].sdate,0,false,'text');WAValidateRQ(document.forms[1].edate,'- Please enter an end date.',document.forms[1].edate,0,false,'text');WAValidateDT(document.forms[1].sdate,'- Invalid date.',true,/.*/,'','','',false,/.*/,'','','',document.forms[1].sdate,0,false);WAValidateDT(document.forms[1].edate,'- Invalid date.',true,/.*/,'','','',false,/.*/,'','','',document.forms[1].edate,0,false);WAValidateRT(document.forms[1].k,document.forms[1].k.value,'- Invalid content in your keyword search.','%7B|%7B, %7D|%7D, %5B|%5B, %5D|%5D, //|//, :|:, ;|;, (|(, )|), =|=, +|+, _|_, http|http, http|http, %5Burl|%5Burl, /url%5D|/url%5D, %25|%25, $|$, #|#, %5Blink|%5Blink, /link%5D|/link%5D',document.forms[0].k,0,false);WAAlertErrors('The following errors were found','Correct invalid entries to continue',true,false,false);return document.MM_returnValue"
Sign in to reply to this post

Nathon Jones Web Design

Thanks man. Fixed it.

On the same website, I have this problem where the time isn't being displayed from an MSSQL datetime field via the following code:

<%IF FormatDateTime((rsEVENT.Fields.Item("tmsastartdate").Value), vbShortTime) >= "00:00" Then %><%ELSE%>
<%IF FormatDateTime((rsEVENT.Fields.Item("tmsastartdate").Value), vbShortTime) >= "11:59" Then %>
<h2><%= FormatDateTime((rsEVENT.Fields.Item("tmsastartdate").Value), vbShortTime) %> pm</h2>
<%ELSE%>
<h2><%= FormatDateTime((rsEVENT.Fields.Item("tmsastartdate").Value), vbShortTime) %> am</h2>
<%End IF%>
<%End IF%>

Here's an event that has this problem:
http://www.tmsa.org.uk/scottish-music-event.asp?e=2085&b=1

The "tmsastartdate" for this event is stored in the datetime field as:
03/12/2014 21:00:00

I appreciate that's above and beyond but I know you're good at spotting things like this. Appreciate it.
NJ

EDIT: Hmm, looking at the code I'm not sure what I was trying to achieve apart from displaying AM or PM. Changed it to this:

<%IF FormatDateTime((rsEVENT.Fields.Item("tmsastartdate").Value), vbShortTime) >= "11:59" Then %>
<h2><%= FormatDateTime((rsEVENT.Fields.Item("tmsastartdate").Value), vbShortTime) %> pm</h2>
<%ELSE%>
<h2><%= FormatDateTime((rsEVENT.Fields.Item("tmsastartdate").Value), vbShortTime) %> am</h2>
<%End IF%>

...and it seems to have resolved it.

Sign in to reply to this post

Jason ByrnesWebAssist

glad to hear it is working.

Sign in to reply to this post

Nathon Jones Web Design

Going back to the original validation error, can you see any reason why it works in IE but Google Chrome is reporting an invalid date?
http://www.tmsa.org.uk/music-events-scotland.asp

Thank you Jason.
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

Looks like chrome doesn't like the dd/mm/yyyy format, if I select a date with the day below 12 it works, chrome only fails if the day is above 12. not sure why that is a problem in chrome, but i suggest changing the date picker format to mm/dd/yyyy instead.

Sign in to reply to this post

Nathon Jones Web Design

Can I use the WebAssist datepicker on this page considering that it's classic ASP?
I have no idea how to change the format because it's an old datepicker from 2006 that I must have found on the web somewhere and I can't see any support for it. It's basically a .js file, which I attach should you be able to spot how I change the format.

Thank you.
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

Yes, the web assist date picker can be used on that page.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...