views:

16

answers:

3

I have an asp DataList as follows.Here I am having a Checkbox and i need to input a number for the corresponding textbox,if I clicked the checkbox.How can I validate it. If I clicked a checkbox I must enter some value(int) to the textbox. Need to validate only for those clicked.Thanks in advance !

 <asp:DataList ID="dlstEnergyItems" runat="server"
 RepeatColumns="4" RepeatDirection="Horizontal"  Width="100%">
         <ItemTemplate>
             <asp:CheckBox ID="cbEnergyItems" runat="server" />
              <asp:HiddenField ID="HdfEnergy" runat="server" />
             <asp:HiddenField ID="HdfEnergyCID" runat="server" />
               <asp:TextBox ID="txtBox" runat="server" />
           </ItemTemplate>
        </asp:DataList>
A: 

insert asp textr boxes for every check box with ajax control validator and make it visibility and validation as false. On the check event make it visible and set true for validation. Hence by using a ajaxcontrol validator you can validate the text box...

Nithesh
@nithesh if a user selects one it will need to execute from server.Suppose if he wants to select 5 items.It will contact server 5 times.Is there any other possible way to do it?
Vishnu K B
dont you know about ajax... use ajax for speed up that
Nithesh
A: 
$("#dlstEnergyItems").find("input[type='checkbox']").change(function(){
 var checkbox = $(this);
 var tr = checkbox.closest("tr");
 var textbox = tr.find("input[type='text']");

 if(!checkbox.is(":selected")){ 
  textbox.unbind("blur");
  return;
 }
 else{
  textbox.focus();
  textbox.blur(function(){
   if(textbox.val().length == 0){
    alert("pls fill textbox");
    textbox.focus();
   }
  });
 }

});

888
A: 

this wors fine for me

 function chkEnergy() {
      var fails = $('.check:has(input:checked)').next("[value=0]").length;
      if (fails > 0) showStatus(true, "Please specify the Quantity");
      return fails === 0;
    }

thnks Nick Craver

Vishnu K B