tom_edwards32
05-12-2003, 08:11 AM
I am attempting to validate a form. Instead of displaying an alert box stating that an error occurred, I am putting an image of a checkmark next to the item(s) that need to be filled in. I have put in two lines of code, one that works by hardcoding the imagename and one that does not work, but need to have work(commented out).
Thanks in advance for help.
HERE IS CODE:
<SCRIPT LANGUAGE="JavaScript">
function showErrorImage(imagename,imageurl) { document[imagename].src = imageurl; }
function allowSubmit(f) {
var strfielderror;
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if (el[i].name.substring(0,8)=="required") {
// when called this way, ok,
showErrorImage("required_Q010615-091515error","images/checkMark.gif");
//but when I call it this way, not ok
// strfielderror = el[i].name+"error";
//
showErrorImage(strfielderror,"images/checkMark.gif");
}
}
}
</SCRIPT>
<html>
<head>
<title> My Survey </title>
</head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0">
<form id="form1" name="form1" method="post" onSubmit="return allowSubmit(this)">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr> <td width='4%' valign='top' >1 </td> <td width='96%' >Choose your favorite color<font color='red'> *</font><img name='required_Q010615-091515error'
src='images/blankImage.gif'></td></tr>
<tr>
<td><input type="submit" name="Submit" value="Submit" ></td></tr> </table> </form> </body> </html>
Thanks in advance for help.
HERE IS CODE:
<SCRIPT LANGUAGE="JavaScript">
function showErrorImage(imagename,imageurl) { document[imagename].src = imageurl; }
function allowSubmit(f) {
var strfielderror;
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if (el[i].name.substring(0,8)=="required") {
// when called this way, ok,
showErrorImage("required_Q010615-091515error","images/checkMark.gif");
//but when I call it this way, not ok
// strfielderror = el[i].name+"error";
//
showErrorImage(strfielderror,"images/checkMark.gif");
}
}
}
</SCRIPT>
<html>
<head>
<title> My Survey </title>
</head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0">
<form id="form1" name="form1" method="post" onSubmit="return allowSubmit(this)">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr> <td width='4%' valign='top' >1 </td> <td width='96%' >Choose your favorite color<font color='red'> *</font><img name='required_Q010615-091515error'
src='images/blankImage.gif'></td></tr>
<tr>
<td><input type="submit" name="Submit" value="Submit" ></td></tr> </table> </form> </body> </html>