Código PHP:
function agregar()
{
if(document.form.referencia.value != "" && document.form.cantidad.value != "" && document.form.descripcion.value != "" && document.form.valor.value != "" &&document.form.descuento.value != ""){
<?php $indice = 0 ?>
document.form.cant<?php echo $indice ?>.style.visibility = 'visible';
document.form.refeprod<?php echo $indice ?>.style.visibility = 'visible';
document.form.desc<?php echo $indice ?>.style.visibility = 'visible';
document.form.valor<?php echo $indice ?>.style.visibility = 'visible';
document.form.valortotal<?php echo $indice ?>.style.visibility = 'visible';
document.form.cant<?php echo $indice ?>.value = document.form.cantidad.value;
document.form.refeprod<?php echo $indice ?>.value = document.form.referencia.value;
document.form.desc<?php echo $indice ?>.value = document.form.descripcion.value;
document.form.valor<?php echo $indice ?>.value = document.form.valor.value;
<?php echo $indice++ ?>
document.form.cantidad.value = "";
document.form.referencia.value = "";
document.form.descripcion.value = "";
document.form.valor.value = "";
}else{
alert('Complete todos los campos antes de agregar el producto a la factura');
}
}