C
canoe414
Greetings all,
I''m trying to write various error messages to placeholder fields
within a form when the data in the corresponding INPUT field is found
to be invalid based upon some criteria.
the INPUT field is:
<td><input name="idnum" type="text" size="20"
onChange="validateTextField(this)"></td>
the placeholder field is:
<td id="msg_idnum"> </font></td>
when validateTextField finds something wrong with the given field I'd
like it to write a predefined string into the placeholder field. I
tried:
document.getElementById('msg_idnum').value = "why does this not
work?";
here's the stripped-down html (and hoping the formatting doesn't get
shredded...)
<pre>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>form validation w/o alerts</title>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-
type">
<script language="JavaScript" type="text/javascript">
<!--
var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function isValid(parm,val) {
if( parm == null || parm == "") return false;
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}
function isNum(parm) {return isValid(parm,numb);}
// in JavaScript zer0 = false , non-zer0 = true
function validateTextField( field_obj, methodofcheck, isRequired) {
var retValue = true;
var fieldname = field_obj.name;
var fieldvalue = field_obj.value;
document.getElementById('msg_idnum').value = "why does this not
work?";
return retValue;
}
function validateForm( form_obj) {
var retValue = true;
var formname = form_object.name;
if( validateTextField(document.forms.login.idnum)) {
document.getElementById('msg_idnum').value = "aarrrrgggghhh";
retValue = false;
}
return retValue;
}
//-->
</script>
</head>
<body>
<form name="login" method="post" onSubmit="return validateForm(this)">
<table>
<tr>
<center>an attempt at form validation w/o alerts</center>
</tr>
<tr>
<td>ID:</td>
<td><input name="idnum" type="text" size="20"
onChange="validateTextField(this)"></td>
<td id="msg_idnum"> </font></td>
</tr>
<tr>
<td>password</td>
<td><input name="passwd" type="password" size="20"></td>
<td id="msg_passwd"> </font></td>
</tr>
<tr>
<td><center><input type="submit" name="signin" value="Sign In"></
center></td>
</tr>
</table>
</form>
</body>
</html>
</pre>
Sooooooo, any ideas?
TIA,
Steve
I''m trying to write various error messages to placeholder fields
within a form when the data in the corresponding INPUT field is found
to be invalid based upon some criteria.
the INPUT field is:
<td><input name="idnum" type="text" size="20"
onChange="validateTextField(this)"></td>
the placeholder field is:
<td id="msg_idnum"> </font></td>
when validateTextField finds something wrong with the given field I'd
like it to write a predefined string into the placeholder field. I
tried:
document.getElementById('msg_idnum').value = "why does this not
work?";
here's the stripped-down html (and hoping the formatting doesn't get
shredded...)
<pre>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>form validation w/o alerts</title>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-
type">
<script language="JavaScript" type="text/javascript">
<!--
var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function isValid(parm,val) {
if( parm == null || parm == "") return false;
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}
function isNum(parm) {return isValid(parm,numb);}
// in JavaScript zer0 = false , non-zer0 = true
function validateTextField( field_obj, methodofcheck, isRequired) {
var retValue = true;
var fieldname = field_obj.name;
var fieldvalue = field_obj.value;
document.getElementById('msg_idnum').value = "why does this not
work?";
return retValue;
}
function validateForm( form_obj) {
var retValue = true;
var formname = form_object.name;
if( validateTextField(document.forms.login.idnum)) {
document.getElementById('msg_idnum').value = "aarrrrgggghhh";
retValue = false;
}
return retValue;
}
//-->
</script>
</head>
<body>
<form name="login" method="post" onSubmit="return validateForm(this)">
<table>
<tr>
<center>an attempt at form validation w/o alerts</center>
</tr>
<tr>
<td>ID:</td>
<td><input name="idnum" type="text" size="20"
onChange="validateTextField(this)"></td>
<td id="msg_idnum"> </font></td>
</tr>
<tr>
<td>password</td>
<td><input name="passwd" type="password" size="20"></td>
<td id="msg_passwd"> </font></td>
</tr>
<tr>
<td><center><input type="submit" name="signin" value="Sign In"></
center></td>
</tr>
</table>
</form>
</body>
</html>
</pre>
Sooooooo, any ideas?
TIA,
Steve