Created
February 22, 2018 00:42
-
-
Save parzibyte/d83e57022949538026ab83061ac48714 to your computer and use it in GitHub Desktop.
Paso 2: insertar datos con PouchDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://cdn.jsdelivr.net/npm/pouchdb@6.4.1/dist/pouchdb.min.js"></script> | |
</head> | |
<body> | |
<h1>Agenda con PouchDB</h1> | |
<a target="_blank" href="https://www.parzibyte.me/blog">https://www.parzibyte.me/blog</a> | |
<br /> | |
<label for="nombreCompleto">Nombre:</label> | |
<br> | |
<input placeholder="Nombre y apellidos" type="text" name="nombreCompleto" id="nombreCompleto" /> | |
<br> | |
<br> | |
<label for="direccion">Dirección:</label> | |
<br> | |
<textarea placeholder="Escribe la dirección..." name="direccion" id=direccion rows="4" cols="30"></textarea> | |
<br> | |
<br> | |
<label for="telefono">Teléfono:</label> | |
<br> | |
<input placeholder="Por ejemplo, 555 222 333" type="tel" name="telefono" id="telefono" /> | |
<br> | |
<br> | |
<button id="btnGuardar">Guardar</button> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bd = new PouchDB("agenda"), | |
$nombreCompleto = document.querySelector("#nombreCompleto"), | |
$direccion = document.querySelector("#direccion"), | |
$telefono = document.querySelector("#telefono"), | |
$btnGuardar = document.querySelector("#btnGuardar"); | |
$btnGuardar.addEventListener("click", function() { | |
var nombreCompleto = $nombreCompleto.value, | |
direccion = $direccion.value, | |
telefono = $telefono.value; | |
if (nombreCompleto && direccion && telefono) { | |
bd.post({ | |
nombre: nombreCompleto, | |
direccion: direccion, | |
telefono: telefono | |
}) | |
.then(function(respuesta) { | |
if (respuesta.ok) { | |
alert("Guardado correctamente"); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment