Vous êtes sur la page 1sur 4

<!

DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Las Tablas Dinamicas</title>
<link rel="shortcut icon" href="Imagenes/icoChiqui.png">
<link rel="stylesheet" type="text/css" href="css/style.css">

<script type="text/javascript">
var tabla1=document.createElement('table');tabla1.setAttribute('id','tabl1');
/******************************La Caja de Texto
Bucar**************************************/
var textbsr=document.createElement('input');
textbsr.setAttribute('type','text');
textbsr.setAttribute('id','txbsrc');
textbsr.setAttribute('onkeyup','Buscar();');

textbsr.style.position='absolute';textbsr.style.top='356px';
textbsr.style.left='400px';
lbcc=document.createElement('label');
lbcc.appendChild(document.createTextNode('Buscar'));
lbcc.setAttribute('id','lb5')
lbcc.style.position='absolute';
lbcc.style.left='600px';
lbcc.style.top='356px';
/******************************La Caja de Texto
Bucar***************************************/

function Seleccionar(x){

Despintar();document.getElementById('txcj').value=tabla1.rows[x.rowIndex].cells[1].
innerHTML;

tabla1.rows[x.rowIndex].style.backgroundColor='#294F66';tabla1.rows[x.rowIndex].sty
le.color='red';

Despintar();document.getElementById('tx2').value=tabla1.rows[x.rowIndex].cells[1].i
nnerHTML;

tabla1.rows[x.rowIndex].style.backgroundColor='#294F66';tabla1.rows[x.rowIndex].sty
le.color='red'

Despintar();document.getElementById('tx3').value=tabla1.rows[x.rowIndex].cells[1].i
nnerHTML;

tabla1.rows[x.rowIndex].style.backgroundColor='#294F66';tabla1.rows[x.rowIndex].sty
le.color='red'
}
function Estamos(){alert('Hola Manes');}

function Buscar(){
var bdr=false;
for(var f=0;f<tabla1.rows.length;f++){ bdr=false;
for(var c=0;c<tabla1.rows[f].getElementsByTagName('td').length && !bdr;c++){

if (document.getElementById('txbsrc').value.toLowerCase().length===0 ||
(tabla1.rows[f].getElementsByTagName('td')
[c].innerHTML.toLowerCase().indexOf(
document.getElementById('txbsrc').value.toLowerCase())>-1))
bdr=true;
}
if (bdr) tabla1.rows[f].style.display='';
else tabla1.rows[f].style.display='none';
}
}

function Despintar(){
for(f=0;f<tabla1.rows.length;f++){
tabla1.rows[f].style.backgroundColor='#7ED8C2';
tabla1.rows[f].style.color='#000000';
}
}

function CrearTabla(ev){
if(document.getElementById('txcj').value.trim().length===0){
alert('No hay Ning�n Dato Importante');
document.getElementById('txcj').focus();
}
else{
if(tabla1.rows.length===4){
alert('La Tabla ya Tiene Todos sus Datos\n Mostraremos sus Datos');
dta=prompt('Ingresa el dato que deseas buscar.....');
p=-1;
for(f=0;f<tabla1.rows.length;f++){
if(dta===tabla1.rows[f].cells[1].innerHTML){
p=f;break;
}
}
if(f<tabla1.rows.length){
Despintar();
tabla1.rows[p].style.backgroundColor='blue';
}
}
else{
/************************Crear y configurara a
Tabla******************************/
tabla1.style.position="absolute";

tabla1.style.top="20px";tabla1.style.left="15px";tabla1.style.color='#ff000';

/************************Crear y configurara la cabecera de la


Tabla***********************/
tbhea=document.createElement('thead');tbhea.style.backgroundColor='blue';

th1=document.createElement('th');th1.appendChild(document.createTextNode('Item'));

th2=document.createElement('th');th2.appendChild(document.createTextNode('Productos
'));
th2.style.width='300px';

th3=document.createElement('th');th3.appendChild(document.createTextNode('Cantidad'
));
th3.style.width='300px';

th4=document.createElement('th');th4.appendChild(document.createTextNode('Precio'))
;
tbhea.appendChild(th1);tbhea.appendChild(th2);tbhea.appendChild(th3);tbhea.appendCh
ild(th4);tabla1.appendChild(tbhea);

/************************Llenar las Filas de la


Tabla***********************/
for(f=1;f<5;f++){
tr=document.createElement('tr');
tr.style.backgroundColor='#7ED8C2';
tr.setAttribute('onclick','Seleccionar(this)');
//tr.addEventListener('keyup',function(event){Estamos();},false);

td1=document.createElement('td');td1.appendChild(document.createTextNode(f));
td2=document.createElement('td');bd=false;prd="";
td3=document.createElement('td');bd=false;pr1="";
td4=document.createElement('td');bd=false;pr2="";
td1.style.textAlign='center';
while(!bd){
prd=prompt('Ingresa el Nombre del Producto '+f);
pr1=prompt('Ingresa el Cantidad del Producto '+f);
pr2=prompt('Ingresa el Precio del Producto '+f);
if(prd.trim().length>0)
bd=true;
}

td2.appendChild(document.createTextNode(prd));tr.appendChild(td1);tr.appendChild(td
2);

td3.appendChild(document.createTextNode(pr1));tr.appendChild(td2);tr.appendChild(td
3);

td4.appendChild(document.createTextNode(pr2));tr.appendChild(td3);tr.appendChild(td
4);
//tr.setAttribute('id',tabla1.rows.length);
tabla1.appendChild(tr);
}
/************************Agregar a la P�gina la
Tabla***********************/
//alert('La tabla Tiene:\n'+tabla1.rows.length+" Filas");
division=document.createElement('div');division.setAttribute('id','div1');
division.appendChild(tabla1);document.body.appendChild(division);
//document.body.appendChild(tabla1);
document.body.appendChild(textbsr);textbsr.focus();
}

}
ev.preventDefault();
}

window.addEventListener('load',function(){
document.getElementById('btn1').addEventListener('click',function(event)
{CrearTabla(event);},false);
//document.getElementById('txbsrc').addEventListener('keyup',function()
{doSearch();},false);
});
</script>
</head>
<body style="background: url(Imagenes/fondo1.jpg) no-repeat center center fixed;
-webkit-background-size: cover;-moz-background-size: cover;-o-background-
size: cover;
background-size: cover; width: 450px;height: 200px">

<div id="Barra1">Formulario</div>
<form id="vta">
<input type="text" name="txcj" id="txcj">
<input type="text" name="txcj" id="tx2">
<input type="text" name="txcj" id="tx3">

<input type="submit" name="btn1" id="btn1" value="Aceptar">


<input type="submit" name="btn1" id="btn2" value="Editar">
<label id="lb4">Producto</label>
<label id="lb2">Cantidad</label>
<label id="lb3">Precio</label>

</form>
</body>
</html>

Vous aimerez peut-être aussi