Click to See Complete Forum and Search --> : Length of String
Asiralia
12-02-2003, 11:54 AM
i have a question. I have an input field and want to insure that the user doesn't forget about the leading zeros when he searches by an agent #.
The only way I thought is to check the lenght of what the user input...
Any suggestions???
Asi
TheBearMay
12-02-2003, 12:14 PM
FieldName.value.length should contain what you're after.
Asiralia
12-02-2003, 12:27 PM
Thank you for your suggestion. I have put the following in the code and it is not working...
<script language="JavaScript">
function validate() {
if (document.form1.control.value.length <8) {
alert("Please check the control # you have entered.");
return false;
}</script>
<div align="right"><b>Agent Number</b></div>
</td>
<td>
<input type="text" name="agt" align="right" size="8" maxlength="8" value=" " tabindex="8" class="textNumber" onsubmit="validate()">
Asi
TheBearMay
12-02-2003, 12:37 PM
Try substituting 'agt' for 'control':
<script language="JavaScript">
function validate() {
if (document.form1.agt.value.length <8) {
alert("Please check the control # you have entered.");
return false;
}
}
</script>
...
<div align="right">
<b>Agent Number</b></div>
</td>
<td>
<form name="form1">
<input type="text" name="agt" align="right" size="8" maxlength="8" value=" " tabindex="8" class="textNumber" onsubmit="validate()">
...
olerag
12-02-2003, 12:48 PM
Asiralia,
Looks like the problem with your example is your missing
the closing brace of your "if" statement.
Asiralia
12-03-2003, 10:44 AM
Thank you so much.
I actually need a minor adjustment it is possible for the input field to have no value...
For the JavaScript to give an error only if they put something in the field that is less than 8 characters...
olerag
12-03-2003, 10:56 AM
In "bears" sample simply extend the "if" clause to test for...
if ((document.form1.agt.value.length > 0) ||
(document.form1.agt.value.length < 8)) {
alert("Your error statement code here");
return(false);
}
olerag
12-03-2003, 11:20 AM
Sorry - change the OR to an AND (&&) test (ouch)...