Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/11/2013, 10:09
czfritz
 
Fecha de Ingreso: agosto-2010
Ubicación: peru
Mensajes: 115
Antigüedad: 13 años, 8 meses
Puntos: 0
como puedo limpiar formulario

hola buen dia amigos de forosdelweb
quiero pedirles ayuda:
como puedo limpiar un formulario despues de enviar que no se quede gravado el comentario y el usuario, que vuelva al ventana inicial.

por favor ayudeme .


Código:
var xmlhttp;
function loadDoc(string,url,cfunc)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(string);
}

function mostrar()
{
	loadDoc(null,"mensajes.php",function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("historial").innerHTML=xmlhttp.responseText;
		}
	  });
}

//setInterval(mostrar,3000);


function agregar()
{
	var u=document.getElementById('nombre').value;
	var c=document.getElementById('comen').value;
	var p=document.getElementById('p').value;

	if((c && u && p)!=""){
		loadDoc("user="+u+"&comen="+c+"&p="+p,"proceso.php",function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("historial").innerHTML=xmlhttp.responseText;
			mostrar();
			}
			
		  });
		  
	}else{ alert("No deje campos vacios"); }

}

y esto es el formulario


Código:
                                <div id="textoc"><textarea id="comen" placeholder="Escriba su Comentario"></textarea></div>
                                <div id="env1">
                                    <div id="user"><input type='text' id="nombre" placeholder="Ingrese su Nombre"></div>
                                    <input id="p" value="pitro" type="hidden">
                                    <div id="envia"><input type='submit' onclick="agregar()" value='PUBLICAR'></div>
                                </div>