Reputation: 15
I have this AJAX form:
function form(){
var icao = document.getElementById('icao').value;
var name = document.getElementById('name').value;
var weightempty = document.getElementById('weightempty').value;
var weightfull = document.getElementById('weightfull').value;
var cargofull = document.getElementById('cargofull').value;
var cruisespeed = document.getElementById('cruisespeed').value;
var range = document.getElementById('range').value;
var price = document.getElementById('price').value;
var firstclassseats = document.getElementById('firstclassseats').value;
var businessclassseats = document.getElementById('businessclassseats').value;
var economyclassseats = document.getElementById('economyclassseats').value;
ajax.open("POST","new_aircraft_process.php",true);
ajax.onreadystatechange=function(){
if(ajax.readyState==4)
{
var respuesta=ajax.responseText;
document.getElementById('result').innerHTML=ajax.responseText;
$("#newaircraftdialog").dialog('close');
refreshTable(function(){$("#loadingdialog").dialog('close');});
}
}
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("icao="+icao+"&name="+name+"&weightempty="+weightempty+"&weightfull="+weightfull+"&cargofull="+cargofull+"&cruisespeed="+cruisespeed+"&range="+range+"&price="+price+"&firstclassseats="+firstclassseats+"&businessclassseats="+businessclassseats+"&economyclassseats="+economyclassseats);
$("#loadingdialog").dialog('open');
}
I want is when the result is displayed (it is a text that says "Successful Form") in the result div is it visible only for 5 seconds and then disappears. I have found various ways, but do not want to delete the div. Because if I want to make the form another time the result of this will have to show again in the div and disappear after 5 seconds after.
Upvotes: 1
Views: 132
Reputation: 23065
You can hide the div and show it later when the form is resubmitted.
ajax.onreadystatechange=function(){
if(ajax.readyState==4)
{
var respuesta=ajax.responseText;
var $result = $('#result');
$result.html(ajax.responseText);
$result.show();
setTimeout(function() { $result.hide() }, 5000);
$("#newaircraftdialog").dialog('close');
refreshTable(function(){$("#loadingdialog").dialog('close');});
}
}
You can also use detach and reattach it to the DOM later.
Upvotes: 0
Reputation: 2707
$('.myDiv').fadeIn(); // Show the div to start.
// All your other code here.
setTimeout(function() { $('.myDiv').fadeOut() }, 5000); // hide the div after we're done
Upvotes: 3