Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2012, 06:35 PM   PM User | #1
sanidhya09
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
sanidhya09 is an unknown quantity at this point
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>
sanidhya09 is offline   Reply With Quote
Old 10-06-2012, 06:46 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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);  
            }
xelawho is offline   Reply With Quote
Old 10-06-2012, 06:46 PM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Tags
two javascript function

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:43 PM.


Advertisement
Log in to turn off these ads.