Ajouter une ligne de facture, stoquer les informations sasies dans la base de do

Signaler
Messages postés
4
Date d'inscription
samedi 2 février 2008
Statut
Membre
Dernière intervention
14 septembre 2011
-
Messages postés
1654
Date d'inscription
dimanche 7 septembre 2008
Statut
Membre
Dernière intervention
11 septembre 2013
-
Bonjour tout le monde,

Je suis entrain de préparer un formulaire de facture dont il y a des champs de saisi...et un bouton en bas nommé "Ajouter" lorsque je clique sur le bouton, une nouvelle ligne s'ajoute à mon formulaire.

J'ai seulement un petit souci, c'est comment ajouter les données saisies dans ma table MySql sachant que le le nombre de lignes de saisie est variable.

Voici Mon code :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns= "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">

// Last updated 2006-02-21
function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'txtRow' + iteration;
el.id = 'txtRow' + iteration;
el.size = 40;

el.onkeypress = keyPressTest;
cellRight.appendChild(el);

// select cell
var cellRightSel = row.insertCell(2);
var sel = document.createElement('select');
sel.name = 'selRow' + iteration;
sel.options[0] = new Option('text zero', 'value0');
sel.options[1] = new Option('text one', 'value1');
cellRightSel.appendChild(sel);
}
function keyPressTest(e, obj)
{
var validateChkb = document.getElementById('chkValidateOnKeyPress');
if (validateChkb.checked) {
var displayObj = document.getElementById('spanOutput');
var key;
if(window.event) {
key = window.event.keyCode;
}
else if(e.which) {
key = e.which;
}
var objId;
if (obj != null) {
objId = obj.id;
} else {
objId = this.id;
}
displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
}
}
function removeRowFromTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
function openInNewWindow(frm)
{
// open a blank window
var aWindow = window.open('', 'TableAddRowNewWindow',
'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');

// set the target to the blank window
frm.target = 'TableAddRowNewWindow';

// submit
frm.submit();
}
function validateRow(frm)
{
var chkb = document.getElementById('chkValidate');
if (chkb.checked) {
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length - 1;
var i;
for (i=1; i<=lastRow; i++) {
var aRow = document.getElementById('txtRow' + i);
if (aRow.value.length <= 0) {
alert('Row ' + i + ' is empty');
return;
}
}
}
openInNewWindow(frm);
}
</script>
</head>



<form action="tableaddrow_nw.html" method="get">
Ma facture |

----

1,
,
<select name ="selRow0">
<option value="value0">text zero</option>
<option value="value1">text one</option>
</select>







</form>



</html>

1 réponse

Messages postés
1654
Date d'inscription
dimanche 7 septembre 2008
Statut
Membre
Dernière intervention
11 septembre 2013
18
bonjour

comment se présente ta table

id,champs1,champs2 ...
que mets tu dans
ttxtRow
selRow
des chiffres lettres ...

<?php
if(isset($_POST['enregistrer']) && $_POST['enregistrer']= =='enregistrer base' &&  !empty($_POST)){
echo '';
print_r($_POST);
echo '

';





/*enregistrer base ... txt ...*/
}else{
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<script type="text/javascript"> 

// Last updated 2006-02-21 
function addRowToTable() 
{ 
var tbl = document.getElementById('tblSample'); 
var lastRow = tbl.rows.length; 
// if there's no header row in the table, then iteration = lastRow + 1 
var iteration = lastRow; 
var row = tbl.insertRow(lastRow); 

// left cell 
var cellLeft = row.insertCell(0); 
var textNode = document.createTextNode(iteration); 
cellLeft.appendChild(textNode); 

// right cell 
var cellRight = row.insertCell(1); 
var el = document.createElement('input'); 
el.type = 'text'; 
el.name = 'txtRow' + iteration; 
el.id = 'txtRow' + iteration; 
el.size = 40; 

el.onkeypress = keyPressTest; 
cellRight.appendChild(el); 

// select cell 
var cellRightSel = row.insertCell(2); 
var sel = document.createElement('select'); 
sel.name = 'selRow' + iteration; 
sel.options[0] = new Option('text zero', 'value0'); 
sel.options[1] = new Option('text one', 'value1'); 
cellRightSel.appendChild(sel); 
} 
function keyPressTest(e, obj) 
{ 
var validateChkb = document.getElementById('chkValidateOnKeyPress'); 
if (validateChkb.checked) { 
var displayObj = document.getElementById('spanOutput'); 
var key; 
if(window.event) { 
key = window.event.keyCode; 
} 
else if(e.which) { 
key = e.which; 
} 
var objId; 
if (obj != null) { 
objId = obj.id; 
} else { 
objId = this.id; 
} 
displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key); 
} 
} 
function removeRowFromTable() 
{ 
var tbl = document.getElementById('tblSample'); 
var lastRow = tbl.rows.length; 
if (lastRow > 2) tbl.deleteRow(lastRow - 1); 
} 
function openInNewWindow(frm) 
{ 
// open a blank window 
var aWindow = window.open('', 'TableAddRowNewWindow', 
'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');

// set the target to the blank window 
frm.target = 'TableAddRowNewWindow'; 

// submit 
frm.submit(); 
} 
function validateRow(frm) 
{ 
var chkb = document.getElementById('chkValidate'); 
if (chkb.checked) { 
var tbl = document.getElementById('tblSample'); 
var lastRow = tbl.rows.length - 1; 
var i; 
for (i=1; i<=lastRow; i++) { 
var aRow = document.getElementById('txtRow' + i); 
if (aRow.value.length <= 0) { 
alert('Row ' + i + ' is empty'); 
return; 
} 
} 
} 
openInNewWindow(frm); 
} 
</script> 
</head> 

 

<form action="" method="post"> 
 Ma facture  |

----

1,
,
<select name ="selRow0">
<option value="value0">text zero</option>
<option value="value1">text one</option>
</select>
 
 
 
 


 

 

</form> 


 
</html>


Bonne programmation !