Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Netscape How to execute two javascript function efficiently

    Whenever i am pressing delete button with two function calls, only one deleteRow() function get executed. But if i use only one deleteme() function on the button click it works fine. Whereas i want to use both the function.

    Code:
    <script type="text/javascript">  
             function deleteme(id){  
                if(confirm('Confirm Deletion')){  
                var f=document.form763;  
                f.method="post";  
                f.action='department_delete.jsp?id='+id;  
                f.submit;    
                } else {//window.location.reload("Department.jsp");  
                }  
                }   
      
                function deleteRow(id){  
                document.getElementById("tableborder3").deleteRow(id);  
                }  
     </script>   
    <td>  
             <input type="submit" name="b1" value="Delete" onClick="deleteme(<%= rs.getString("department_id") %>);deleteRow(<%=rs.getRow()%>);" />  
     </td>

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,882
    Thanks
    56
    Thanked 539 Times in 536 Posts
    deleteRow() is a native javascript method, but by calling your function the same name it appears that you are redefining it, sending the code into an endless loop as you call the function from within the function. depending on what value <%=rs.getRow()%> gives, you may not even need that function, and could just call deleteRow() from the button and be done with it. More likely, though you would want to rename the function and do something like this:

    Code:
         <input type="button" name="b1" value="Delete" onClick="deleteme(<%= rs.getString("department_id") %>);deleteR(<%=rs.getRow()%>);" /> //also note no need for a submit button here
    
    function deleteR(id){  
                document.getElementById("tableborder3").deleteRow(id);  
                }

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    function deleteRow(id){  
    document.getElementById("tableborder3").deleteRow(id);  
    }
    I assume id as a row-index-number and not actually an id-number? But your functions is named deleteRow() which over-writes the DOM deleteRow() method. So your function just calls itself recursively without deleting anything.

    Change the name of your function to something other than deleteRow() and (I recommend for clarity) rename the parameter to perhaps ind, or index.

    xelawho is shadowing me, or me him
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •