Kermit_The_Frog | c'est effectivement plus pratique au niveau du codage
Par contre, je viens de terminer d'adapter la première version à mes besoins. voici le code HTML généré par PHP
Code :
- <html>
- <head>
- <title>-- Qualifications - professional trainings -- Solid Partners' Knowledge Management System</title>
- <link rel="stylesheet" href="kms.css" type="text/css">
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <!-- these scripts are used to add/remove lines in the tables -->
- <script language="Javascript" src="scripts/add_remove_line_qualifications.js">
- </script>
- <script language="Javascript" src="scripts/add_remove_line_prof_trainings.js">
- </script>
- </head>
- <body>
- <form name="qualTrainForm" method="GET"
- action="qualif_prof_trainings.php?mode=insert&employee_id=789798">
- <br>
- <!-- premier tableau -->
- <div align="center">Qualifications</div>
- <br>
- <table id="tbQual" border="1">
- <TR>
- <TH><div align="center">from (dd-mm-yyyy)</div></TH>
- <TH><div align="center">to (dd-mm-yyyy)</div></TH>
- <TH><div align="center">qualification</div></TH>
- <TH><div align="center">course attended</div></TH>
- <TH><div align="center">diploma obtained</div></TH>
- <TH><div align="center">distinction</div></TH>
- <TH><div align="center">dissertation</div></TH>
- <TH></TH>
- <TH></TH>
- </TR>
- </table>
- <br>
- <!-- deuxième tableau -->
- <div align="center">Professional trainings</div>
- <br>
- <table id="tbTrain" border="1">
- <TR>
- <TH><div align="center">date (dd-mm-yyyy)</div></TH>
- <TH><div align="center">institution</div></TH>
- <TH><div align="center">subject</div></TH>
- <TH><div align="center">module</div></TH>
- <TH><div align="center">technology sector</div></TH>
- <TH><div align="center">business sector</div></TH>
- <TH><div align="center">certification</div></TH>
- <TH></TH>
- <TH></TH>
- </TR>
- </table>
- <!-- chargement des deux tableaux -->
- <body onload="addQual();addTrain();">
- <br>
- <div align="center">
- <input type="submit" name="create" value="create">
- </div>
- </form>
- <BR>
- </body>
- </html>
|
et les deux fonctions javascript fort proches l'une de l'autre, mais bon soyons complet add_remove_line_qualifications.js
Code :
- <!--
- var nbQual=0;
- var numLinesQual = 0; //number of lines in the table
- //header for the table
- HEADERTABLEQUAL = '<TR><TH><div align="center">from (dd-mm-yyyy)</div></TH>'
- + '<TH><div align="center">to (dd-mm-yyyy)</div></TH>'
- + '<TH><div align="center">qualification</div></TH>'
- + '<TH><div align="center">course attended</div></TH>'
- + '<TH><div align="center">diploma obtained</div></TH>'
- + '<TH><div align="center">distinction</div></TH>'
- + '<TH><div align="center">dissertation</div></TH>'
- + '<TH></TH>'
- + '<TH></TH>'
- + '</TR>';
- //default values used to initialize the fields
- DEFVALUESQUAL = new Array ("00-00-0000","00-00-0000",false,false,false,false,"" );
- //function to delete the specified line
- function delLineQual( x )
- {
- var tb = '';
- numLinesQual--;
- for( i=1; i<=nbQual; i++ )
- {
- if( x != i ){
- if( i < x ){
- j = i;
- }
- else{
- j = i - 1;
- }
- //to get back the values of the fields
- var savedValues = new Array(
- document.getElementById('from_date'+i).value,
- document.getElementById('to_date'+i).value,
- document.getElementById('qualification_id'+i).value,
- document.getElementById('course_attended'+i).value,
- document.getElementById('diploma_obtained'+i).value,
- document.getElementById('distinction'+i).value,
- document.getElementById('dissertation'+i).value);
- tb = tb + genLigneQual( j , savedValues );
- }
- }
- if( document.all ){
- document.getElementById('tbQual').outerHTML =
- '<table id="tbQual" border="1">'
- + HEADERTABLEQUAL + tb
- + '</table>';
- }
- else{
- document.getElementById('tbQual').innerHTML = HEADERTABLEQUAL + tb;
- }
- nbQual--;
- }
- //function to insert a line
- function insertLineQual( x )
- {
- var tb = '';
- numLinesQual++;
- for( i=1; i<=nbQual; i++ ){
- if( x == i ){
- tb = tb + genLigneQual( i , DEFVALUESQUAL );
- }
- if( i < x ){
- j = i;
- }
- else{
- j = i + 1;
- }
- //to get back the values of the fields
- var savedValues = new Array(
- document.getElementById('from_date'+i).value,
- document.getElementById('to_date'+i).value,
- document.getElementById('qualification_id'+i).value,
- document.getElementById('course_attended'+i).checked,
- document.getElementById('diploma_obtained'+i).checked,
- document.getElementById('distinction'+i).checked,
- document.getElementById('dissertation'+i).value);
- tb = tb + genLigneQual( j , savedValues );
- }
- if( document.all ){
- document.getElementById('tbQual').outerHTML =
- '<table id="tbQual" border="1">'
- + HEADERTABLEQUAL + tb
- + '</table>';
- }
- else{
- document.getElementById('tbQual').innerHTML = HEADERTABLEQUAL + tb;
- }
- nbQual++;
- }
- //function to initialize the table
- function addQual()
- {
- var tb = '';
- nbQual++;
- numLinesQual++;
- tb = document.getElementById('tbQual').innerHTML
- + genLigneQual( nbQual , DEFVALUESQUAL );
- if( document.all ){
- document.getElementById('tbQual').outerHTML =
- '<table id="tbQual" border="1">'
- + tb + '</table>';
- }
- else{
- document.getElementById('tbQual').innerHTML = tb;
- }
- }
- function genLigneQual( num , fieldValues )
- {
- var strReturn = '<tr id="tr' + num + '">'
- + '<TD><INPUT TYPE="TEXT" NAME="from_date-' + num
- + '" ID="from_date' + num + '" VALUE="' + fieldValues[0]
- + '" SIZE="10" MAXLENGTH="10">'
- + '<font color="#FF0000" size="3"><B> * </B></font></TD>'
- + '<TD><INPUT TYPE="TEXT" NAME="to_date-' + num
- + '" ID="to_date' + num + '" VALUE="' + fieldValues[1]
- + '" SIZE="10" MAXLENGTH="10">'
- + '<font color="#FF0000" size="3"><B> * </B></font></TD>'
- + '<TD><SELECT NAME="qualification_id-' + num
- + '" SIZE="1" ID="qualification_id' + num + '">'
- + '<OPTION VALUE="0" SELECTED>Java Engineer - Sun - Bruxelles - Belgium</OPTION>'
- + '</SELECT><font color="#FF0000" size="3"><B> * </B></font>'
- + '<INPUT TYPE="submit" NAME="qualifications" VALUE="New"'
- + ' ID="qualifications' + num + '"></TD>';
- if (fieldValues[3] == true){
- //used to know if the checkbox was checked or not
- strReturn = strReturn + '<TD width ="30">'
- + '<INPUT TYPE="CHECKBOX" NAME="course_attended-'
- + num + '" VALUE="course_attended-' + num
- + '" ID="course_attended' + num + '" CHECKED>';
- }
- else{
- strReturn = strReturn + '<TD width="30">'
- + '<INPUT TYPE="CHECKBOX" NAME="course_attended-'
- + num + '" VALUE="course_attended-' + num
- + '" ID="course_attended' + num + '">';
- }
- strReturn = strReturn + '<font color="#FF0000" size="3"><B> * </B></font></TD>';
- if (fieldValues[4] == true){
- strReturn = strReturn + '<TD width="35">'
- + '<INPUT TYPE="CHECKBOX" NAME="diploma_obtained-'
- + num + '" VALUE="diploma_obtained-' + num
- + '" ID="diploma_obtained' + num +'" CHECKED>';
- }
- else{
- strReturn = strReturn + '<TD width="35">'
- + '<INPUT TYPE="CHECKBOX" NAME="diploma_obtained-'
- + num + '" VALUE="diploma_obtained-' + num
- + '" ID="diploma_obtained' + num +'">';
- }
- strReturn = strReturn + '<font color="#FF0000" size="3"><B> * </B></font></TD>';
- if (fieldValues[5] == true){
- strReturn = strReturn + '<TD><INPUT TYPE="CHECKBOX" NAME="distinction-'
- + num + '" VALUE="distinction-' + num + '" ID="distinction'
- + num + '" CHECKED></TD>';
- }
- else{
- strReturn = strReturn + '<TD><INPUT TYPE="CHECKBOX" NAME="distinction-'
- + num + '" VALUE="distinction-' + num + '" ID="distinction'
- + num +'"></TD>';
- }
- strReturn = strReturn + '<TD><INPUT TYPE="TEXT" NAME="dissertation-' + num
- + '" ID="dissertation' + num
- + '" VALUE="' + fieldValues[6]
- + '" SIZE="30" MAXLENGTH="100"></TD>'
- + '<TD><img type="button" src="images/add_line.jpg" '
- + 'onclick="insertLineQual(' + num + ');" '
- + 'alt="insert a line before this one"></img></TD>';
- //to avoid the user to delete the line if it's the only one in the table
- if (numLinesQual > 1){
- strReturn = strReturn + '<TD><img type="button" '
- + 'src="images/rem_line.jpg" onclick="delLineQual(' + num
- + ');" alt="remove this line"></img></TD>';
- }
- return(strReturn);
- }
- -->
|
add_remove_line_prof_trainings.js
Code :
- <!--
- var nbTrain=0;
- var numLinesTrain = 0; //number of lines in the table
- //header for the table
- HEADERTABLETRAIN = '<TR><TH><div align="center">date (dd-mm-yyyy)</div></TH>'
- + '<TH><div align="center">institution</div></TH>'
- + '<TH><div align="center">subject</div></TH>'
- + '<TH><div align="center">module</div></TH>'
- + '<TH><div align="center">technology sector</div></TH>'
- + '<TH><div align="center">business sector</div></TH>'
- + '<TH><div align="center">certification</div></TH>'
- + '<TH></TH>'
- + '<TH></TH>'
- + '</TR>';
- //default values used to initialize the fields
- DEFVALUESTRAIN = new Array ("00-00-0000","","","","","",false);
-
- //function to delete the specified line
- function delLineTrain( x )
- {
- var tb = '';
- numLinesTrain--;
- for( i=1; i<=nbTrain; i++ )
- {
- if( x != i )
- {
- if( i < x )
- {
- j = i;
- }
- else
- {
- j = i - 1;
- }
- //to get back the values of the fields
- var savedValues = new Array(
- document.getElementById('date'+i).value,
- document.getElementById('institution'+i).value,
- document.getElementById('subject'+i).value,
- document.getElementById('module'+i).value,
- document.getElementById('technology_sector'+i).value,
- document.getElementById('business_sector'+i).value,
- document.getElementById('certification'+i).value);
- tb = tb + genLigneTrain( j , savedValues );
- }
- }
- if( document.all )
- {
- document.getElementById('tbTrain').outerHTML =
- '<table id="tbTrain" border="1">'
- + HEADERTABLETRAIN + tb
- + '</table>';
- }
- else
- {
- document.getElementById('tbTrain').innerHTML = HEADERTABLETRAIN + tb;
- }
- nbTrain--;
- }
- //function to insert a line
- function insertLineTrain( x )
- {
- var tb = '';
- numLinesTrain++;
- for( i=1; i<=nbTrain; i++ )
- {
- if( x == i )
- {
- tb = tb + genLigneTrain( i , DEFVALUESTRAIN );
- }
- if( i < x )
- {
- j = i;
- }
- else
- {
- j = i + 1;
- }
- //to get back the values of the fields
- var savedValues = new Array(
- document.getElementById('date'+i).value,
- document.getElementById('institution'+i).value,
- document.getElementById('subject'+i).value,
- document.getElementById('module'+i).value,
- document.getElementById('technology_sector'+i).value,
- document.getElementById('business_sector'+i).value,
- document.getElementById('certification'+i).checked);
- tb = tb + genLigneTrain( j , savedValues );
- }
- if( document.all )
- {
- document.getElementById('tbTrain').outerHTML =
- '<table id="tbTrain" border="1">'
- + HEADERTABLETRAIN + tb
- + '</table>';
- }
- else
- {
- document.getElementById('tbTrain').innerHTML = HEADERTABLETRAIN + tb;
- }
- nbTrain++;
- }
- //function to initialize the table
- function addTrain()
- {
- var tb = '';
- nbTrain++;
- numLinesTrain++;
- tb = document.getElementById('tbTrain').innerHTML
- + genLigneTrain( nbTrain , DEFVALUESTRAIN );
- if( document.all )
- {
- document.getElementById('tbTrain').outerHTML =
- '<table id="tbTrain" border="1">'
- + tb + '</table>';
- }
- else
- {
- document.getElementById('tbTrain').innerHTML = tb;
- }
- }
- function genLigneTrain( num , fieldValues )
- {
- var strReturn = '<tr id="tr' + num + '">'
- + '<TD><INPUT TYPE="TEXT" NAME="date-' + num
- + '" ID="date' + num + '" VALUE="' + fieldValues[0]
- + '" SIZE="10" MAXLENGTH="10">'
- + '<font color="#FF0000" size="3"><B> * </B></font></TD>'
- + '<TD><INPUT TYPE="TEXT" NAME="institution-' + num
- + '" ID="institution' + num + '" VALUE="' + fieldValues[1]
- + '" SIZE="20" MAXLENGTH="50">'
- + '<font color="#FF0000" size="3"><B> * </B></font></TD>'
- + '<TD><INPUT TYPE="TEXT" NAME="subject-' + num
- + '" ID="subject' + num + '" VALUE="' + fieldValues[2]
- + '" SIZE="20" MAXLENGTH="50">'
- + '<font color="#FF0000" size="3"><B> * </B></font></TD>'
- + '<TD><INPUT TYPE="TEXT" NAME="module-' + num
- + '" ID="module' + num + '" VALUE="' + fieldValues[3]
- + '" SIZE="20" MAXLENGTH="50">'
- + '<font color="#FF0000" size="3"><B> * </B></font></TD>'
- + '<TD><INPUT TYPE="TEXT" NAME="technology_sector-' + num
- + '" ID="technology_sector' + num
- + '" VALUE="' + fieldValues[4]
- + '" SIZE="20" MAXLENGTH="50">'
- + '<font color="#FF0000" size="3"><B> * </B></font></TD>'
- + '<TD><INPUT TYPE="TEXT" NAME="business_sector-' + num
- + '" ID="business_sector' + num + '" VALUE="' + fieldValues[5]
- + '" SIZE="20" MAXLENGTH="50"></TD>';
- if (fieldValues[6] == true){
- strReturn = strReturn + '<TD><INPUT TYPE="CHECKBOX" NAME="certification-'
- + num + '" VALUE="certification-' + num + '" ID="certification'
- + num + '" CHECKED></TD>';
- }
- else{
- strReturn = strReturn + '<TD><INPUT TYPE="CHECKBOX" NAME="certification-'
- + num + '" VALUE="certification-' + num + '" ID="certification'
- + num +'"></TD>';
- }
- strReturn = strReturn + '<TD><img type="button" src="images/add_line.jpg" '
- + 'onclick="insertLineTrain(' + num + ');" '
- + 'alt="insert a line before this one"></img></TD>';
- //to avoid the user to delete the line if it's the only one in the table
- if (numLinesTrain > 1){
- strReturn = strReturn + '<TD><img type="button" '
- + 'src="images/rem_line.jpg" onclick="delLineTrain(' + num
- + ');" alt="remove this line"></img></TD>';
- }
- return(strReturn);
- }
- -->
|
voilà, j'espère que l'affichage ne sera pas trop pourri parce que je n'arrive pas à voir jusqu'où je peux aller avec une ligne Je vais sans doute m'atteler à la modif' de ta dernière version le Barbu j'ai encore une question pratique (décidément, ce topic vire de plus ne plus franchement vers le javascript) : je voudrais ouvrir une popup lors du click sur un lien (ou un bouton) lié à un champ afin de permettre au user de choisir une valeur dans une liste (par exemple) et ensuite remplir le champ avec cette valeur. Le problème est le passage du nom du champ à remplir pour pouvoir utiliser une affectation du type :
window.opener.document.forms[0].nomChamp.value = valeurRecupérée
je vais faire une recherche sur le forum javascript mais si tu as une idée ...
|