javascript working in mozilla validating only one field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shyamg
    New Member
    • Jun 2007
    • 28

    #1

    javascript working in mozilla validating only one field

    Hi,

    this is my javascript validating the fields in mozilla FF but its working and validating only one field.

    how to write the and how to works the script ............... ...

    [code=javascript]
    function Test(){


    alphaNumericInp ut(document.for ms[0].dealerid);

    digitsAlphabets Input(document. forms[0].dealerid); //for digits only
    alphabetsInput( document.forms[0].dealerid);//only alpha bets

    }

    function digitsInput(tex tField){
    var regExp=/^[0-9]*$/;
    if(textField.va lue=="" || regExp.test(tex tField.value))
    return false;

    alert("Only digits are allowed!");
    textField.value = textField.value .replace(/[^0-9]/g,"");
    }
    function alphabetsInput( textField){
    var regExp=/^[a-z A-Z]*$/;
    if(textField.va lue=="" || regExp.test(tex tField.value))
    return;

    alert("Only alphabets symbols are allowed!");
    textField.value = textField.value .replace(/[^a-z A-Z]/g,"");
    }
    var regExp=/^[0-9\a-z A-Z]*$/;
    textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");

    function digitsAlphabets Input(textField ){
    var regExp=/^[0-9\a-z A-Z]*$/;
    if(textField.va lue=="" || regExp.test(tex tField.value))
    return;

    alert("Only digits and alphabets are allowed!");
    textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");
    }


    [/code]

    Thanks

    ss.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, SS.

    In test(), you're passing the same form element each time. Is this intentional?

    Comment

    • shyamg
      New Member
      • Jun 2007
      • 28

      #3
      [CODE=javascript]
      function Test(){


      alphaNumericInp ut(document.for ms[0].dealerid);

      alphabetsInput( document.forms[0].name);
      alphabetsInput( document.forms[0].lname);

      }

      function digitsInput(tex tField){
      var regExp=/^[0-9]*$/;
      if(textField.va lue=="" || regExp.test(tex tField.value))
      return false;

      alert("Only digits are allowed!");
      textField.value = textField.value .replace(/[^0-9]/g,"");
      }
      function alphabetsInput( textField){
      var regExp=/^[a-z A-Z]*$/;
      if(textField.va lue=="" || regExp.test(tex tField.value))
      return;

      alert("Only alphabets symbols are allowed!");
      textField.value = textField.value .replace(/[^a-z A-Z]/g,"");
      }
      var regExp=/^[0-9\a-z A-Z]*$/;
      textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");

      function digitsAlphabets Input(textField ){
      var regExp=/^[0-9\a-z A-Z]*$/;
      if(textField.va lue=="" || regExp.test(tex tField.value))
      return;

      alert("Only digits and alphabets are allowed!");
      textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");
      }

      [/CODE]

      i am passing differet values through the Body Onload. but it is checking only one first one. The above given is some of my sample code.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, SS.

        You did not declare a function named alphaNumericInp ut(). Did you mean digitsAlphabets Input()?

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          hi ...

          please have a close look at your script and the comments that i made within:

          [CODE=javascript]
          function Test(){
          // like pbmods said ... the following function is not declared
          // and in your initial post all fields where 'dealerid' ...
          alphaNumericInp ut(document.for ms[0].dealerid);

          alphabetsInput( document.forms[0].name);
          alphabetsInput( document.forms[0].lname);
          }

          function digitsInput(tex tField){
          var regExp=/^[0-9]*$/;

          if(textField.va lue=="" || regExp.test(tex tField.value)) return false;

          alert("Only digits are allowed!");

          textField.value = textField.value .replace(/[^0-9]/g,"");
          }

          function alphabetsInput( textField){
          var regExp=/^[a-z A-Z]*$/;

          if(textField.va lue=="" || regExp.test(tex tField.value)) return;

          alert("Only alphabets symbols are allowed!");

          textField.value = textField.value .replace(/[^a-z A-Z]/g,"");
          }

          // the following two lines are useless i think ... they are executed
          // during load and assign an regEx that is never used and
          // should give an error since textField is undefined here
          var regExp=/^[0-9\a-z A-Z]*$/;

          textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");

          function digitsAlphabets Input(textField ){
          var regExp=/^[0-9\a-z A-Z]*$/;

          if(textField.va lue=="" || regExp.test(tex tField.value)) return;

          alert("Only digits and alphabets are allowed!");

          textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");
          }
          [/CODE]

          fixing the function-name in the test-function should do the job. and a strict way to write down the code with strict indentation will help you a lot when searching matching brackets or useless lines of code ... delete them since they produce an error in our actual case ...

          kind regards

          Comment

          • shyamg
            New Member
            • Jun 2007
            • 28

            #6
            Originally posted by gits
            hi ...

            please have a close look at your script and the comments that i made within:

            [CODE=javascript]
            function Test(){
            alphaNumericInp ut(document.for ms[0].dealerid);

            alphabetsInput( document.forms[0].name);
            alphabetsInput( document.forms[0].lname);
            }

            function digitsInput(tex tField){
            var regExp=/^[0-9]*$/;

            if(textField.va lue=="" || regExp.test(tex tField.value)) return false;

            alert("Only digits are allowed!");

            textField.value = textField.value .replace(/[^0-9]/g,"");
            }

            function alphabetsInput( textField){
            var regExp=/^[a-z A-Z]*$/;

            if(textField.va lue=="" || regExp.test(tex tField.value)) return;

            alert("Only alphabets symbols are allowed!");

            textField.value = textField.value .replace(/[^a-z A-Z]/g,"");
            }

            function digitsAlphabets Input(textField ){
            var regExp=/^[0-9\a-z A-Z]*$/;

            if(textField.va lue=="" || regExp.test(tex tField.value)) return;

            alert("Only digits and alphabets are allowed!");

            textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");
            }
            [/CODE]
            i removied that two lins also iam still geting same proble .now its not validating any field.


            ss

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              ;) you missed the first comment, and pbmods mentioned it too:

              [CODE=javascript]function Test(){
              // there is no function called alphaNumericInp ut declared in your script
              // you will get an error that alphaNumericInp ut is not a function
              alphaNumericInp ut(document.for ms[0].dealerid);
              alphabetsInput( document.forms[0].name);
              alphabetsInput( document.forms[0].lname);
              }[/CODE]

              declare that function or use the correct name of the function you want to use ...

              kind regards

              Comment

              • shyamg
                New Member
                • Jun 2007
                • 28

                #8
                [CODE=javascript]function Test(){
                digitsInput(doc ument.forms[0].dealerid);
                alphabetsInput( document.forms[0].name);
                alphabetsInput( document.forms[0].lname);
                }[/CODE]

                iam using like this also not working do u know any validation script urls plz send that urls . ok
                TQ

                kind regards

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  ... that's really confusing now, the following example works and uses all the code you provided ...

                  [HTML]<html>
                  <head>
                  <script>
                  function Test(){
                  digitsInput(doc ument.forms[0].dealerid);
                  alphabetsInput( document.forms[0].name);
                  alphabetsInput( document.forms[0].lname);
                  }

                  function digitsInput(tex tField){
                  var regExp=/^[0-9]*$/;

                  if(textField.va lue=="" || regExp.test(tex tField.value))r eturn false;

                  alert("Only digits are allowed!");
                  textField.value = textField.value .replace(/[^0-9]/g,"");
                  }

                  function alphabetsInput( textField){
                  var regExp=/^[a-z A-Z]*$/;

                  if(textField.va lue=="" || regExp.test(tex tField.value)) return;

                  alert("Only alphabets symbols are allowed!");

                  textField.value = textField.value .replace(/[^a-z A-Z]/g,"");
                  }

                  function digitsAlphabets Input(textField ){
                  var regExp=/^[0-9\a-z A-Z]*$/;

                  if(textField.va lue=="" || regExp.test(tex tField.value)) return;

                  alert("Only digits and alphabets are allowed!");

                  textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");
                  }
                  </script>
                  </head>
                  <body>
                  <form name="my_form">
                  <input type="text" name="dealerid"/>
                  <input type="text" name="name"/>
                  <input type="text" name="lname"/>
                  <input type="button" value="Validate " onclick="Test() ;"/>
                  </form>
                  </body>
                  </html>
                  [/HTML]

                  have a look at the firefox-javascript-console ... there has to be another error besides the one we found already ... how do you call Test();?

                  kind regards

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    ... or another guess ... how should it work? may be it works for us but you want it to work another way? ...

                    Comment

                    • shyamg
                      New Member
                      • Jun 2007
                      • 28

                      #11
                      hi

                      now iam using like this

                      iam getting this error in the console


                      Error: illegal character
                      Source File: http://ad.doubleclick. net/adj/ttm.thescripts/webdev/jsajax;cmy=webd ev;zn=jsajax;sz =728x90;tile=1; ord=891731041?
                      Line: 1, Column: 6
                      Source Code:
                      GIF89a



                      Code:
                       function Test(){
                       
                        alert("doSubmit"+document.forms[0].dscpt.value);
                        
                       
                         digitsInput(document.forms[0].icno);
                         digitsInput(document.forms[0].id1);
                         alphabetsInput( document.forms[0].name);
                         digitsInput(document.forms[0].groupid);
                        }
                      
                       function digitsInput(textField){
                       var regExp=/^[0-9]*$/;
                       if(textField.value=="" || regExp.test(textField.value)) 
                        return false;
                       
                       alert("Only digits are allowed!");
                       textField.value = textField.value.replace(/[^0-9]/g,"");
                       }
                       function alphabetsInput(textField){
                       var regExp=/^[a-z A-Z]*$/;
                       if(textField.value=="" || regExp.test(textField.value)) 
                        return;
                       
                       alert("Only alphabets symbols are allowed!");
                       textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
                      }
                      
                       
                      function digitsAlphabetsInput(textField){
                       var regExp=/^[0-9\a-z A-Z]*$/;
                       if(textField.value=="" || regExp.test(textField.value)) 
                        return;
                       
                       alert("Only digits and alphabets are allowed!");
                       textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
                      }

                      Thanks gits.

                      Comment

                      • shyamg
                        New Member
                        • Jun 2007
                        • 28

                        #12
                        hi

                        now iam using like this

                        iam getting this error in the console


                        Error: illegal character
                        Source File: http://ad.doubleclick.net/adj/ttm.th...ord=891731041?
                        Line: 1, Column: 6
                        Source Code:
                        GIF89a

                        if i click the error iam getting like this

                        GIF89a��€��ÿÿ ÿ���!ù����,�� ����� D�;


                        and iam calling the function like this in the body

                        <body onload="Test()" >

                        Thanks gits

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5390

                          #13
                          heya shyamg,

                          is it working now or not? try the posted example and have a look whether you want this behaviour or not. if not ... then tell us what it is supposed to do.

                          do you get the alert you have now in your Test();-function? ... and again: when and how do you call this function? can you post more code? as we can see in the above example the lines we have are working ...

                          kind regards

                          Comment

                          • gits
                            Recognized Expert Moderator Expert
                            • May 2007
                            • 5390

                            #14
                            hmmm ... we posted at the same time ...

                            you validate the form onload? do you expect wrong entrys at this time? are the values prefilled in any way?

                            but thats not our original problem ;) ... is the example working for you? in that case your script should work too except of other errors that we may find when you post some more code ...

                            kind regards

                            Comment

                            • anbumozhip
                              New Member
                              • Jul 2007
                              • 10

                              #15
                              hi
                              u replied something abt converting dbf files to postgres could you please be specific .i'm a beginner please help me.

                              Comment

                              Working...