Click to See Complete Forum and Search --> : Script error message


californiasteve
07-23-2003, 08:33 AM
I have a validation script I have adapted from someone else. It works on the page by inserting graphics letting the person know the fields are blank or incorrect. When it gets to the end of the function I get a "function expected" error message and then the form submits. I'm still pretty new at this so any help would be appreciated. Sorry about the long code but not quite sure what I should post yet. Steve

Code: <script language="JavaScript">
<!-- Begin
// Preload images
var empty = new image(); empty.src = "images/fieldempty.gif";
var email = new image(); email.src = "images/emailerror.gif";
var haveerrors = 0;

function showImage(imagename, imageurl, errors) {
document[imagename].src = imageurl;
if (!haveerrors && errors) haveerrors = errors;
}

function validateForm(f) {
haveerrors = 0;
(f.area.value.length <1)
? showImage("areaerror", "images/fieldempty.gif", true)
: showImage("areaerror", "images/blankimage.gif", false);

(f.name.value.length <1)
? showImage("nameerror", "images/fieldempty.gif", true)
: showImage("nameerror", "images/blankimage.gif", false);

(f.address.value.length <1)
? showImage("addresserror", "images/fieldempty.gif", true)
: showImage("addresserror", "images/blankimage.gif", false);

(f.contact.value.length <1)
? showImage("contacterror", "images/fieldempty.gif", true)
: showImage("contacterror", "images/blankimage.gif", false);

(f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1)
(f.name.value.length <1)
? showImage("emailerror", "images/emailerror.gif", true)
: showImage("emailerror", "images/blankimage.gif", false);
return (!haveerrors);
}
// End -->
</script>

<form action="cf_activities.cfm" method="post" enctype="multipart/form-data" name="activities" id="activities" onSubmit="return validateForm(this);">
<p><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Area /
Group:</strong></font>
<input name="area" type="text" id="area">
<font color="ff0000">*</font> <strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif">Event
Name:
<input name="name" type="text" id="name" maxlength="30">
</font></strong> <font color="ff0000">*</font> <br>
<img name=areaerror src="images/blankimage.gif" size=25 maxlength=50>
<img src="images/blankimage.gif" name=nameerror size=25 maxlength=50></p>
<p><strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif">Start
Date &nbsp;
<a href="javascript:show_calendar('activities.startdate');"
onmouseover="window.status='Date Picker';return true;"
onmouseout="window.status='';return true;">
<img src="images/show-calendar.gif" width="24" height="22"></a href>
&nbsp;
<input name="startdate" type="text" id="startdate" value="&lt;--- Click on Calendar">
Start Time
<select name="starttime" size="1">
<option value="1am">1 AM</option>
<option value="2am">2 AM</option>
<option value="3am">3 AM</option>
<option value="4am">4 AM</option>
<option value="5am">5 AM</option>
<option value="6am">6 AM</option>
<option value="7am">7 AM</option>
<option value="8am">8 AM</option>
<option value="9am">9 AM</option>
<option value="10am">10 AM</option>
<option value="11am">11 AM</option>
<option value="12pm">12 PM</option>
<option value="1pm">1 PM</option>
<option value="2pm">2 PM</option>
<option value="3pm">3 PM</option>
<option value="4pm">4 PM</option>
<option value="5pm">5 PM</option>
<option value="6pm" selected>6 PM</option>
<option value="7pm">7 PM</option>
<option value="8pm">8 PM</option>
<option value="9pm">9 PM</option>
<option value="10pm">10 PM</option>
<option value="11pm">11 PM</option>
<option value="12am">12 AM</option>
</select>
</font></strong></p>
<p><strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif">End Date <a href="javascript:show_calendar('activities.enddate');"
onmouseover="window.status='Date Picker';return true;"
onmouseout="window.status='';return true;">
<img src="images/show-calendar.gif" width="24" height="22"></a href>
&nbsp;
<input name="enddate" type="text" id="enddate" value="&lt;--- Click on Calendar">
End Time
<select name="endtime" size="1">
<option value="1am">1 AM</option>
<option value="2am">2 AM</option>
<option value="3am">3 AM</option>
<option value="4am">4 AM</option>
<option value="5am">5 AM</option>
<option value="6am">6 AM</option>
<option value="7am">7 AM</option>
<option value="8am">8 AM</option>
<option value="9am">9 AM</option>
<option value="10am">10 AM</option>
<option value="11am">11 AM</option>
<option value="12pm">12 PM</option>
<option value="1pm">1 PM</option>
<option value="2pm">2 PM</option>
<option value="3pm">3 PM</option>
<option value="4pm">4 PM</option>
<option value="5pm">5 PM</option>
<option value="6pm">6 PM</option>
<option value="7pm">7 PM</option>
<option value="8pm">8 PM</option>
<option value="9pm">9 PM</option>
<option value="10pm">10 PM</option>
<option value="11pm">11 PM</option>
<option value="12am" selected>12 AM</option>
</select>
</font></strong></p>
<p><strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif">Address
<input name="address" type="text" id="address" value="address, city, state, zip">
<font color="ff0000">*</font><br>
<img src="images/blankimage.gif" name=addresserror id="addresserror" size=25 maxlength=50>
</font></strong></p>
<p> <font size="3" face="Geneva, Arial, Helvetica, sans-serif"><strong>Contact:
<input name="contact" type="text" id="contact">
<font color="ff0000" size="3" face="Geneva, Arial, Helvetica, sans-serif">
*</font> E-Mail
<input name="email" type="text" id="email">
<font color="ff0000" size="3" face="Geneva, Arial, Helvetica, sans-serif">
*</font></strong></font><br>
<strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif"><img src="images/blankimage.gif" name=contacterror id="contacterror" size=25 maxlength=50></font></strong>
<strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif"><img src="images/blankimage.gif" name=emailerror id="emailerror" size=25 maxlength=50></font></strong>
</p>
<p><font size="3" face="Geneva, Arial, Helvetica, sans-serif"><strong>Website
<input name="website" type="text" id="website" value="http://www.website.com">
Upload Flyer
<input type="file" name="fileurl" value="">
</strong></font></p>
<p><strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif">Give
us a short description:
<textarea name="description" cols="30" rows="5" id="description"></textarea>
</font></strong></p>
<p><strong><font size="3" face="Geneva, Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Submit">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Submit2" value="Clear">
&nbsp;&nbsp;&nbsp;&nbsp;</font></strong> </p>

</form>

AdamBrill
07-23-2003, 08:44 AM
Ok... First of all, on these lines:

var empty = new image(); empty.src = "images/fieldempty.gif";
var email = new image(); email.src = "images/emailerror.gif";

the "i" in image should be capitalized. Like this:

var empty = new Image(); empty.src = "images/fieldempty.gif";
var email = new Image(); email.src = "images/emailerror.gif";

Second, the submit error is generated by this line:

(f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1)

My guess is that it should be like this:


(f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1)
? showImage("emailerror", "images/emailerror.gif", true)
: showImage("emailerror", "images/blankimage.gif", false);

But then I don't know what you want to do with this line:

(f.name.value.length <1)

Anyway, those are the errors. I hope I wasn't too confusing. ;) Let me know if you have any more problems with it. :)

californiasteve
07-23-2003, 09:00 AM
Hey Adam: That fixed it. The other line in the E-mail validation I forgot to put the || after the line before. Once again thanks for the info. Steve

AdamBrill
07-23-2003, 09:09 AM
No Problem, I'm glad that fixed the problem. ;)