Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using javascript for gridview cells validation in clientside.it shows alert successfully .but return true.this is my problem.advance thanks
JavaScript
<script type="text/javascript">
                    function trim(str) {
                        return str.replace(/^\s*/g, '').replace(/\s*$/g, '');
                       
                    }
                    function bvalidate(event) {
                        debugger;
                        var txt1 = document.getElementById("txt1").value;
                        var grid = document.getElementById("GridView1");
//                        var cell;
                        if (txt1 == null || txt1 == "") 
                        {
                            alert("country cannot be empty ")
                            return false;
                        }


                        if (grid != null) 
                        {
                            for (var i = 1; i <= grid.rows.length - 1; i++) 
                            {
//                              cell = grid.rows[i].cells[1].innerText;
                              if (trim(grid.rows[i].cells[1].innerText) == trim(txt1)) {
                                  alert("Item Already Exits")
                                  return false;
                                }
                             
                            }
                            return false;

                        }
                        
                        
                    }
                    
                </script>
Posted
Updated 21-Aug-12 19:36pm
v2
Comments
AmitGajjar 22-Aug-12 1:38am    
can you post your code from you are calling javascript ?
Vasim889 22-Aug-12 2:15am    
<asp:Button ID="Button1" runat="server" Text="save" OnClientClick="return bvalidate(event)" onclick="Button1_Click" /> .
AmitGajjar 22-Aug-12 2:20am    
First/Second which alert box appear ?
AmitGajjar 22-Aug-12 2:21am    
have you try to debug your javascript ?
Vasim889 22-Aug-12 3:25am    
ya i also check in debugger , second alert retrieve.but return true in default script block in explorer and then going on server side.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900