...

View Full Version : How to execute two javascript function efficiently



sanidhya09
10-06-2012, 06:35 PM
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.


<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>

xelawho
10-06-2012, 06:46 PM
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:


<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);
}

AndrewGSW
10-06-2012, 06:46 PM
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 ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum