By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

textbox inside the datagrid using javascript

P: 5
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
Jan 2 '08 #1
Share this Question
Share on Google+
6 Replies


Frinavale
Expert Mod 5K+
P: 9,731
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
Jan 2 '08 #2

P: 11
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="javascript:IsNumeric(this.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
Jan 2 '08 #3

Frinavale
Expert Mod 5K+
P: 9,731
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="javascript:IsNumeric(this.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
Jan 2 '08 #4

P: 11
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
Expand|Select|Wrap|Line Numbers
  1. function IsNumeric(strString)
  2.    //  check for valid numeric strings    
  3.    {
  4.    var strValidChars = "0123456789.-";
  5.    var strChar;
  6.    var blnResult = true;
  7.  
  8.    if (strString.length == 0) return false;
  9.  
  10.    //  test strString consists of valid characters listed above
  11.    for (i = 0; i < strString.length && blnResult == true; i++)
  12.       {
  13.       strChar = strString.charAt(i);
  14.       if (strValidChars.indexOf(strChar) == -1)
  15.          {
  16.          blnResult = false;
  17.          }
  18.       }
  19.    return blnResult;
  20.    }
  21.  
Hope this was useful

With regards,
ram
Jan 2 '08 #5

P: 5
Expand|Select|Wrap|Line Numbers
  1. function IsNumeric(strString)
  2.    //  check for valid numeric strings    
  3.    {
  4.    var strValidChars = "0123456789.-";
  5.    var strChar;
  6.    var blnResult = true;
  7.  
  8.    if (strString.length == 0) return false;
  9.  
  10.    //  test strString consists of valid characters listed above
  11.    for (i = 0; i < strString.length && blnResult == true; i++)
  12.       {
  13.       strChar = strString.charAt(i);
  14.       if (strValidChars.indexOf(strChar) == -1)
  15.          {
  16.          blnResult = false;
  17.          }
  18.       }
  19.    return blnResult;
  20.    }
  21.  
Hope this was useful

With regards,
ram


Consider my grid having many textbox.And the number of textbox is not always constant.Suppose 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.
Jan 3 '08 #6

Frinavale
Expert Mod 5K+
P: 9,731
Consider my grid having many textbox.And the number of textbox is not always constant.Suppose 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...from there you can loop through and check if the name matches the textboxes in your GridView:

Expand|Select|Wrap|Line Numbers
  1.     var all = document.getElementsByTagName('input');
  2.     var len = all.length;
  3.     for(var i = 0; i < len; i++)
  4.    {
  5.        var temp = all[i];
  6.        //if this temp variable is one of the textboxes in your
  7.        //GridView...Do Something .....
  8.    }
-Frinny
Jan 3 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.