This is a migrated thread and some comments may be shown as answers.

Disable textbox in RadGrid using Javascript/JQuery

4 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Atchut
Top achievements
Rank 1
Atchut asked on 28 Apr 2012, 04:42 PM
Hello,

I have 2 textboxes in same row. I want to disable the other textbox, if text changes in one textbox.

How can I do this using Javascript/ Jquery.?

I have multiple grids in the same page.

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 29 Apr 2012, 07:19 AM
Hello Atchut,

<telerik:GridTemplateColumn>
                       <ItemTemplate>
                           <telerik:RadTextBox ID="RadTextBox1" runat="server">
                               <ClientEvents OnValueChanging="ValueChanged"/>
                           </telerik:RadTextBox>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
                   <telerik:GridTemplateColumn>
                       <ItemTemplate>
                           <telerik:RadTextBox ID="RadTextBox2" runat="server">
                                
                           </telerik:RadTextBox>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
<script type="text/javascript">
 
            function ValueChanged(sender, args) {
                var senderid = sender.get_id();
                var strtext = $find(senderid).get_value();
                var txt2 = $find(senderid.replace('RadTextBox1', 'RadTextBox2'));
                if (strtext.length > 0) {
                    txt2.set_enabled(false);
                    
                }
                else {
                    txt2.set_enabled(true);
                    
                }
                 
            }
 
        </script>


Thanks,
Jayesh Goyani
0
Atchut
Top achievements
Rank 1
answered on 29 Apr 2012, 07:23 PM
Hello Jayesh,

Thanks for your response. The script is working but still I am able to enter text into disbaled textbox.
What would be the reason?
0
Atchut
Top achievements
Rank 1
answered on 29 Apr 2012, 07:25 PM
Hello Jayesh,

It is because tab is moving to next textbox. I have to disable that tab also.
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Apr 2012, 06:36 AM
Hello,

<telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <telerik:RadTextBox ID="RadTextBox1" runat="server">
                                <ClientEvents OnValueChanging="ValueChanged" />
                            </telerik:RadTextBox>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <telerik:RadTextBox ID="RadTextBox2" runat="server">
                            <ClientEvents OnKeyPress="KeyPres" />
                            </telerik:RadTextBox>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

function ValueChanged(sender, args) {
                
               var senderid = sender.get_id();
               var strtext = $find(senderid).get_value();
               var txt2 = $find(senderid.replace('RadTextBox1', 'RadTextBox2'));
               if (strtext.length > 0) {
                   txt2.set_enabled(false);
 
               }
               else {
                   txt2.set_enabled(true);
 
               }
 
           }
 
           function KeyPres(sender, arge) {
               if (sender.get_enabled() == false) {
                   arge.set_cancel(true);
               }
           }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Atchut
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Atchut
Top achievements
Rank 1
Share this question
or