locked
Javscript not working onmouseover RRS feed

  • Question

  • User2033107836 posted

    Hello

    This is my ASP Page

    <script type="text/javascript" language="javascript">
    
    function CheckNumber(lnk) {
        var row = lnk.parentNode.parentNode;
        var rowIndex = row.rowIndex - 1;
        
        var field2 = row.cells[4].getElementsByTagName("span")[0].innerHTML;
    
        var field4 = row.cells[9].getElementsByTagName("span")[0].innerHTML;
    
        if (parseInt(field4) > parseInt(field2))
        
            alert("Please Check Loan Chemical Qty V/S Given Chemical Qty...!");
        
        return false;
    }
    
    </script>
    
    
    
    <asp:Button ID="z" runat="server" AccessKey="A" Text="Add Item" onmouseover="CheckNumber(this);" TabIndex="11" OnClick="z_Click" Width="93px" 
                 style="background-image: url(images/btn_5.png)" BackColor="Transparent" BorderColor="Transparent"
                  BorderStyle="Dashed" BorderWidth="1px" Font-Bold="True" Font-Names="Palatino Linotype" Font-Size="10pt" ForeColor="#FFFFFF" Height="39px" /> 

    On button mouse over validation not working why

    Wednesday, November 9, 2016 9:22 AM

Answers

  • User-691209617 posted

    Please check below mention code.

     function CheckNumber(lnk) {
    
            var row = lnk.parentNode.parentNode;
            var rowindex = row.rowIndex - 1;
    
            var i, CellValue, Row, td;
            i = parseInt(rowindex);
    
            var table = document.getElementById('<%=Gridview1.ClientID %>');
    
                Row = table.rows[i];
                td = Row.cells[4];
                CellValue = td.children[0].attributes[0].value;
                var field2 =parseInt(document.getElementById(CellValue).innerText);
                td = Row.cells[9];
                CellValue = td.children[0].attributes[0].value;
                var field4 = parseInt(document.getElementById(CellValue).innerText);
                if (field4 > field2)
                    alert("Please Check Loan Chemical Qty V/S Given Chemical Qty...!");
    
                return false;
        }

    Hope it helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 9, 2016 2:51 PM

All replies

  • User527778624 posted

    Hi,

    check the button has onmouseover at clientside (browser).

    check browser console for any errors after mouseover.

    check parentNode.parentNode is a <tr> tag, and it has rowIndex property.

    Wednesday, November 9, 2016 1:23 PM
  • User475983607 posted

    On button mouse over validation not working why

    Basically, the script is tightly bound to the HTML which his not good design. If the HTML structure changes then you 'll need to update the script.  

    There is no way that anyone on these forums can tell you why the code is not work because we cannot see the HTML.  

    I suggest that you take advantage of Developer Tools (F12) to debug your work.  All major bowers have this feature.  

    https://developer.chrome.com/devtools

    Also, JQuery makes querying the DOM much easier as it uses selectors rather than hardcoded approach.

    Wednesday, November 9, 2016 2:01 PM
  • User-691209617 posted

    Please check below mention code.

     function CheckNumber(lnk) {
    
            var row = lnk.parentNode.parentNode;
            var rowindex = row.rowIndex - 1;
    
            var i, CellValue, Row, td;
            i = parseInt(rowindex);
    
            var table = document.getElementById('<%=Gridview1.ClientID %>');
    
                Row = table.rows[i];
                td = Row.cells[4];
                CellValue = td.children[0].attributes[0].value;
                var field2 =parseInt(document.getElementById(CellValue).innerText);
                td = Row.cells[9];
                CellValue = td.children[0].attributes[0].value;
                var field4 = parseInt(document.getElementById(CellValue).innerText);
                if (field4 > field2)
                    alert("Please Check Loan Chemical Qty V/S Given Chemical Qty...!");
    
                return false;
        }

    Hope it helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 9, 2016 2:51 PM