...

View Full Version : Online form - Text Box won't accept a capital A



bluegenel
06-07-2007, 10:44 AM
I have the code below in an online form. Basically there is just 1 problem, the field won't accept a capital A. When I press down the A on the keyboard the A appears, but then disappears when I let go.

Any help with this is most appreciated. Here is the javascript code and the code for the field. I am using Windows XP and MS FrontPage 2000.

<script language="JavaScript" type="text/javascript">
<!--
function clrtxt1(formnm)
{
var txtbox;

for (var i = 0; i < formnm.elements.length-1; i++)
{
txtbox = formnm.elements[i];
if (txtbox.name == "budget_code_1")
{
txtbox.value = "A _ _ _ ";
}
}
}
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
function Format2(lstr){ // lstr is the variable passed to the function
if (/^[A][ ][A-Z0-9][ ][A-Z0-9][ ][AB][ ]$/i.test(lstr.value)){
lstr.value = lstr.value.toUpperCase();
}
else
{
lstr.value = "";
alert(" A Budget Code field is incorrect - Please see text above ");
}
}
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
function Format(obj){
string='A _ _ _ '
val=obj.value.replace(/_/g,'');
val=val.replace(/A/g,'');
val=val.replace(/\s/g,'');
val1=''
for (zxc0=0;zxc0<val.length;zxc0++){
val1+=val.charAt(zxc0)+' ';
}
if (val1.length<0){
obj.value=val1+string.substring(val1.length,string.length);
}
else{
val2=val1.substring(0,0)+'A '+val1.substring(6,0);
obj.value=val2+string.substring(val2.length,string.length);
}
}

//-->
</script>


The field:-

<!--webbot bot="Validation" B-Value-Required="TRUE" I-Minimum-Length="8" -->
<input onkeyup="Format(this);" onblur="Format2(this);" onkeypress="Format(this);" size="9" name="budget_code_1" onfocus="clrtxt1(this.form);">

Philip M
06-07-2007, 12:55 PM
val=val.replace(/A/,''); (delete the g switch)

Delete: onkeypress="Format(this);" (you already have an onkeyup statement)

That seems to fix it.

bluegenel
06-07-2007, 01:12 PM
Excellent thanks Philip. It works a treat.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum