Q: form validation withOUT alerts

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">&nbsp;</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">&nbsp;</font></td>
</tr>
<tr>
<td>password</td>
<td><input name="passwd" type="password" size="20"></td>
<td id="msg_passwd">&nbsp;</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
 
D

David Mark

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">&nbsp;</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?";

It does not work as you are trying to treat a table cell like an input
element. Either change the element to a read-only text, use the
innerText property of the table cell or create a text node and insert
it into the table cell.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
oglegroups.com>, Tue, 17 Jul 2007 03:33:27, canoe414@telecom-
digest.zzn.com posted:
Sooooooo, any ideas?

Any attempt to do validation in ISO-16262 javascript without using
RegExps is pure folly. The time wasted would be far better spent in
learning elementary RegExps.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
J

jidixuelang

Please try "document.getElementById('msg_idnum').innerHTML" or
"document.getElementById('msg_idnum').Text",first!
 
J

jidixuelang

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">&nbsp;</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">&nbsp;</font></td>
</tr>
<tr>
<td>password</td>
<td><input name="passwd" type="password" size="20"></td>
<td id="msg_passwd">&nbsp;</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

Please try "document.getElementById('msg_idnum').innerHTML" or
"document.getElementById('msg_idnum').innerText" before!
 
O

One Dumm Hikk

It does not work as you are trying to treat a table cell like an input
element. Either change the element to a read-only text, use the
innerText property of the table cell or create a text node and insert
it into the table cell.

innerHTML would be a better choice, especially for innerText, would it
not? Its support is very wide spread and trivial to implement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top