Originariamente inviato da Xinod
codice:
function tuaFunzione(bla){
...
return false; // = non vuoi inviare il form
}
...
<form onsubmit="return tuaFunzione('blablabla')">
Ok, ma così non si sposta più su http://www.yahoo.com...
codice:
<html>
<head>
<script type="text/javascript">
var xml_http_obj = false;
if (window.XMLHttpRequest){
//Firefox, safari etc
xml_http_obj = new XMLHttpRequest();
}else if(window.ActiveXObject){
//Microsoft IE
xml_http_obj = new ActiveXObject("Microsoft.XMLHTTP");
}
function get_data(url,wait_div_id){
if (xml_http_obj){
xml_http_obj.open("GET",url,true);
xml_http_obj.onreadystatechange = function(){
if (xml_http_obj.readyState == 4 && xml_http_obj.status == 200){
document.getElementById(wait_div_id).style.visibility="hidden";
}else{
document.getElementById(wait_div_id).style.visibility="visible";
}
}
xml_http_obj.send(null);
}
return false;
}
</script>
<style>
div#wait{
background-color:white;
position:absolute;
top:240px;
left:360px;
width:400px;
height:50px;
visibility:hidden;
border: 0px;
padding:0px;
}
</style>
</script>
</head>
<body id="body">
<H1>Please Wait AJAX </H1>
<form action="http://www.yahoo.com" method="post" onSubmit="return get_data('go_to_sleep.php','wait')">
<div id="wait" >
[img]wait.gif[/img]Please wait ...
</div>
<input type="submit" value="Search">
</form>
</body>
</html>