In my web application(using Zend Framework) when adding a new entity to the database, it should check whether this entity has previously been added and deleted. (When deleting an entity from the database, that particular record’s “STATUS” column is updated to 0(zero).)
If the entity has deleted earlier, the system asks for confirmation to edit the previously deleted record, or add a new record. If the user needs to edit the previously added record, user should be redirected to the edit page.
This check and redirecting is done using jQuery. Here is the jQuery code I’m using:
$("input[name=btnSubmit]").click(function(){
var name = $("input[name=txtTblPrefix]").val();
var parameters = 'name='+name;
$.ajax({
url: '../admin_mapping/get-id',
async:false,
data:parameters,
type:'POST',
dataType: 'text',
success: function(data)
{
var res = confirm("There is a record already added to the database for "+name+". Do you want to edit it?");
if(res)
{
window.location.replace("../admin_mapping/edit?id="+data);
}
}
});
});
In this code, everything works perfectly other than the redirecting. I have tested the line window.location.replace("../admin_mapping/edit?id="+data); separately and it works fine. Even the confirm() function returns true.
I have tried putting an alert() inside the if condition, and the alert prompts. But the redirecting is not working.
Can anyone please help me with this?
Thanks in advance
The only thing I need to do is put a
return falseinside thesubmitfunction. Otherwise as the button is a submit button, the form gets submitted.