Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Online form - Text Box won't accept a capital A

    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);">

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    val=val.replace(/A/,''); (delete the g switch)

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

    That seems to fix it.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Excellent thanks Philip. It works a treat.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •