asp.net gridview textbox focus using javascript -


i developing asp.net application have content page derived master page , inside page have gridview control have bound fields , textbox take value , calculate remaining. using following javascript code.

     <td colspan="4">    <div id="divgrid" style="width: 890px; height: 200px; overflow: auto">       <asp:gridview id="customergrid" runat="server" backcolor="white" autogeneratecolumns="false"           bordercolor="#336666" borderstyle="double" borderwidth="3px" cellpadding="4"            gridlines="horizontal" width="920px">           <rowstyle backcolor="white" forecolor="#333333" />          <%-- <headerstyle cssclass="headerfreeze" />--%>           <columns>               <asp:boundfield datafield="ref_no" headertext="deal/transfer ref # " >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" width="180px" forecolor="blue" font-bold="true" />               </asp:boundfield>               <asp:boundfield datafield="settlement_date" headertext="settlement date" >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>               <asp:boundfield datafield="settlement_amount" headertext="settlement amt" >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>               <asp:boundfield datafield="interest_rate" headertext="interest rate" >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>               <asp:boundfield datafield="pdealername" headertext="primary dealer" >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>               <asp:boundfield datafield="pd_price" headertext="pd price" >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>                <asp:templatefield headertext="facevalue">                  <itemtemplate>                      <asp:label id="lblfacevalue" runat="server" text='<%# eval("face_value") %>'></asp:label>                  </itemtemplate>                  <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:templatefield>                                 <%-- <asp:boundfield datafield="face_value" headertext="face value" >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>--%>                <asp:boundfield datafield="available" headertext="available" >                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>               <asp:templatefield headertext="value">               <itemtemplate>                   <asp:textbox id="txtvalue" runat="server" width="100px" onblur="calculatetotals();"></asp:textbox>               </itemtemplate>                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />                </asp:templatefield>               <asp:templatefield headertext="remaining">                   <itemtemplate>                       <asp:label id="lblremaining" runat="server" text=""></asp:label>                   </itemtemplate>                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:templatefield>                <asp:boundfield datafield="transaction_type" headertext="t" visible="false">                   <headerstyle font-names="verdana" font-size="11px" />                   <itemstyle font-names="verdana" font-size="11px" />               </asp:boundfield>           </columns>           <footerstyle backcolor="white" forecolor="#333333" />           <pagerstyle backcolor="#336666" forecolor="white" horizontalalign="center" />           <selectedrowstyle backcolor="#339966" font-bold="true" forecolor="white" />           <headerstyle backcolor="#336666" font-bold="true" forecolor="white" />       </asp:gridview>       </div>       &nbsp;</td> <script type="text/javascript">  function calculatetotals() {     var gv = document.getelementbyid("<%= customergrid.clientid %>");     var tb = gv.getelementsbytagname("input");     var lb = gv.getelementsbytagname("span");      var sub = 0;     var total = 0;     var indexq = 1;     var indexp = 0;      (var = 0; < tb.length; i++) {         if (tb[i].type == "text") {             sub = parsefloat(lb[indexp].innerhtml) - parsefloat(tb[i].value);             if (sub < 0)              {                 alert("exceeding face value...");                 return;                 tb[i].focus();                 //return;             }              if (isnan(sub)) {                 lb[i + indexq].innerhtml = "";                 sub = 0;             }             else {                 lb[i + indexq].innerhtml = sub;             }              indexq++;             indexp = indexp + 2;              total += parsefloat(sub);         }     } }   </script> 

problem have condition input value cannot exceed face value..if exceeds shows alert..i want show error , focus should textbox control of particular row. somehow not setting focus textbox control of particular row.

just check area need modification.

if (sub < 0)          {             alert("exceeding face value...");             return;             tb[i].focus();             //return;         } 

any suggestions?

the return before call focus. focus never called way code is.

alert("exceeding face value..."); return; tb[i].focus(); 

should be

alert("exceeding face value..."); tb[i].focus(); return; 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -