textbox inside the datagrid using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • venkateshcnpl
    New Member
    • Jan 2008
    • 5

    textbox inside the datagrid using javascript

    Hi,I am New To This .
    I have to check the duplications of values entered in textbox which is placed inside the datagrid using javascript

    .And the Number of textbox is not constant it is dynamically added can any one solve this
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by venkateshcnpl
    Hi,I am New To This .
    I have to check the duplications of values entered in textbox which is placed inside the datagrid using javascript

    .And the Number of textbox is not constant it is dynamically added can any one solve this
    What have you tried so far to solve this problem?

    -Frinny

    Comment

    • Ramchandar
      New Member
      • Dec 2007
      • 11

      #3
      Originally posted by venkateshcnpl
      Hi,I am New To This .
      I have to check the duplications of values entered in textbox which is placed inside the datagrid using javascript

      .And the Number of textbox is not constant it is dynamically added can any one solve this
      Hi,
      Two approaches.
      1. Check the text entered in the textbox is numeric or not using the onblur event of the textbox. This would be something like this.
      <asp:GridView ID="GridView1" runat="server">
      .
      .
      <asp:TextBox ID="txtNo" runat="server" onblur="javascr ipt:IsNumeric(t his.value);"></asp:TextBox>
      .
      .
      </asp:GridView>

      2. Have a global javascript variable which will be concatenated with the id of the dynamically added textboxes.
      Upon click of the submit button use this variable to get the id's and check for their value.

      hope this suggestion would be useful..

      With regards,
      ram

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by Ramchandar
        Hi,
        Two approaches.
        1. Check the text entered in the textbox is numeric or not using the onblur event of the textbox. This would be something like this.
        <asp:GridView ID="GridView1" runat="server">
        .
        .
        <asp:TextBox ID="txtNo" runat="server" onblur="javascr ipt:IsNumeric(t his.value);"></asp:TextBox>
        .
        .
        </asp:GridView>

        2. Have a global javascript variable which will be concatenated with the id of the dynamically added textboxes.
        Upon click of the submit button use this variable to get the id's and check for their value.

        hope this suggestion would be useful..

        With regards,
        ram
        Could you also post your JavaScript.
        (Please place your code snippets within [code] tags...see the posting guidelines for information on how to use these tags)

        -Frinny

        Comment

        • Ramchandar
          New Member
          • Dec 2007
          • 11

          #5
          Originally posted by Frinavale
          Could you also post your JavaScript.
          (Please place your code snippets within
          Code:
           tags...see [URL=http://www.thescripts.com/forum/faq.php?faq=posting_guidelines#faq_how_to_ask_a_question]the posting guidelines[/URL] for information on  how to use these tags)
          
          -Frinny
          Code:
          [CODE=javascript]
          function IsNumeric(strString)
             //  check for valid numeric strings	
             {
             var strValidChars = "0123456789.-";
             var strChar;
             var blnResult = true;
          
             if (strString.length == 0) return false;
          
             //  test strString consists of valid characters listed above
             for (i = 0; i < strString.length && blnResult == true; i++)
                {
                strChar = strString.charAt(i);
                if (strValidChars.indexOf(strChar) == -1)
                   {
                   blnResult = false;
                   }
                }
             return blnResult;
             }
          Hope this was useful

          With regards,
          ram
          Last edited by Frinavale; Jan 3 '08, 02:07 PM. Reason: Fixed Code Tag

          Comment

          • venkateshcnpl
            New Member
            • Jan 2008
            • 5

            #6
            Originally posted by Ramchandar
            [CODE=javascript]
            function IsNumeric(strSt ring)
            // check for valid numeric strings
            {
            var strValidChars = "0123456789 .-";
            var strChar;
            var blnResult = true;

            if (strString.leng th == 0) return false;

            // test strString consists of valid characters listed above
            for (i = 0; i < strString.lengt h && blnResult == true; i++)
            {
            strChar = strString.charA t(i);
            if (strValidChars. indexOf(strChar ) == -1)
            {
            blnResult = false;
            }
            }
            return blnResult;
            }
            [/CODE]

            Hope this was useful

            With regards,
            ram


            Consider my grid having many textbox.And the number of textbox is not always constant.Suppos e if am entereing 'thescripts' in one textbox and the same also in another textbox ,it should throw error.

            Kindly note the number of textbox in the grid is not constant.
            I can do this in server side ,since i want to do this in Jvascript kindy help me.
            Last edited by Frinavale; Jan 3 '08, 02:08 PM. Reason: Fixed QuoteTag

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by venkateshcnpl
              Consider my grid having many textbox.And the number of textbox is not always constant.Suppos e if am entereing 'thescripts' in one textbox and the same also in another textbox ,it should throw error.

              Kindly note the number of textbox in the grid is not constant.
              I can do this in server side ,since i want to do this in Jvascript kindy help me.
              You're still going to need to do this check Server Side because it's easy to get around JavaScript validations.

              Anyways...there 's a way to grab all the input fields using JavaScript...fr om there you can loop through and check if the name matches the textboxes in your GridView:

              [code=javascript]
              var all = document.getEle mentsByTagName( 'input');
              var len = all.length;
              for(var i = 0; i < len; i++)
              {
              var temp = all[i];
              //if this temp variable is one of the textboxes in your
              //GridView...Do Something .....
              }[/code]

              -Frinny

              Comment

              Working...