BrutAlow | Bonjour,
j'expose ici mon probleme de somme d'addition de 4 inputs
Code :
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
- <head>
- <title>Calcul</title>
-
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <link rel="stylesheet" href="style_tarif.css"></link>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js"></script>
- <script type="text/javascript" src="javascript.js"></script>
- </head>
- <body>
- <div id="bloc_page">
- <table>
- <caption>PRIX VAISSEAUX LEGERS DE BASE</caption>
- <thead>
- <tr>
- <th class="type_v">Nom vaisseaux</th>
- <th class="type">Nombres vaisseaux</th>
- <th class="type">Plutonium</th>
- <th class="type">Acier</th>
- <th class="type">Xenon</th>
- <th class="type">Hydrogene</th>
- <th class="type">Points</th>
- <th class="type">Tirs</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <th style="text-align: left">Chasseurs Legers</th>
- <th><span id="cl_nbre" value="0">0</span></th>
- <th>
- <input id="input_ships_clpu" type="text" onkeyup="Calcul('ships','clpu', 'cl');" value="0" name="input_ships_clpu"/>
- <input id="datas_ships_clpu" type="hidden" value="210:0:0:0:1:1" name="datas_ships_clpu"/>
- </th>
- <th>
- <input id="input_ships_clac" type="text" onkeyup="Calcul('ships','clac', 'cl');" value="0" name="input_ships_clac"/>
- <input id="datas_ships_clac" type="hidden" value="0:750:0:0:1:1" name="datas_ships_clac"/>
- </th>
- <th>
- <input id="input_ships_clxe" type="text" onkeyup="Calcul('ships','clxe', 'cl');" value="0" name="input_ships_clxe"/>
- <input id="datas_ships_clxe" type="hidden" value="0:0:620:0:1:1" name="datas_ships_clxe"/>
- </th>
- <th>
- <input id="input_ships_clhy" type="text" onkeyup="Calcul('ships','clhy', 'cl');" value="0" name="input_ships_clhy"/>
- <input id="datas_ships_clhy" type="hidden" value="0:0:0:300:1:1" name="datas_ships_clhy"/>
- </th>
- <th><span id="cl_points">0</span></th>
- <th><span id="cl_tirs">0</span></th>
- </tr>
- </tbody>
- </table>
- </div>
- </body>
- </html>
|
Code :
- function Calcul(type, element, vaisseau){
- number = parseInt($('#input_'+type+'_'+element).val());
- if( (number < 0) || (isNaN(number) == true) ){ number = 0 ; }
- nbres = $('#datas_'+type+'_'+element).val();
- nbre = nbres.split(":" );
- if(number > 0){ Cost_pluto = number / parseInt(nbre[0]); } else { Cost_pltuo = parseInt(nbre[0]) ; }
- if(number > 0){ Cost_acier = number / parseInt(nbre[1]); } else { Cost_acier = parseInt(nbre[1]) ; }
- if(number > 0){ Cost_xenon = number / parseInt(nbre[2]); } else { Cost_xenon = parseInt(nbre[2]) ; }
- if(number > 0){ Cost_hydro = number / parseInt(nbre[3]); } else { Cost_hydro = parseInt(nbre[3]) ; }
-
- Cost_nbre = parseInt(Cost_pluto);
- //Cost_nbre = parseInt( Cost_pluto + Cost_acier + Cost_xenon + Cost_hydro );
-
- if(number > 0){ Cost_points = parseInt(nbre[4] * Cost_nbre); } else { Cost_points = parseInt(nbre[4]) ; }
- if(number > 0){ Cost_tirs = parseInt(nbre[5] * Cost_nbre); } else { Cost_tirs = parseInt(nbre[5]) ; }
-
- $('#'+vaisseau+'_nbre').text(Add_Sep_Pt(parseInt(Cost_nbre)));
- $('#'+vaisseau+'_points').text(Add_Sep_Pt(Cost_points));
- $('#'+vaisseau+'_tirs').text(Add_Sep_Pt(Cost_tirs));
- }
- function Add_Sep_Pt(nbre){
- var str_nbre = "";
- for (cpt = nbre.toString().length - 3; cpt >= 0; cpt = cpt - 3 )
- {
- str_nbre = nbre.toString().substr(cpt, 3) + "." + str_nbre;
- }
- if ( (nbre.toString().length % 3) != 0 )
- str_nbre = nbre.toString().substr(0, nbre.toString().length % 3) + "." + str_nbre;
- str_nbre = str_nbre.substr(0, str_nbre.length - 1);
- return (str_nbre);
- }
|
Sachant que j'ai 20 lignes de 4 inputs
Help me please !!! Une question peut on utiliser plusieurs split() dans une meme fonction ??
|