Jump to content
php.lv forumi

CheckBox vērtību saskaitīšana


Zoom

Recommended Posts

Man ir 10 checkboxi. Iekeķsējot atsevišķu boxsus man saskaitās to vērtības. Es domāju to ielikt ciklā. Kur atķeksēti tiek saskaitīti. Un attiecīgi, ja atķeksē atpakaļ, tad tā vērtība atņemas. Pareizi domāju?

Link to comment
Share on other sites

kam tev to vajag ?

Es tādiem gadījumiem taisu bin2dec()

strBin = "";
for (i=0;i<checkBoxCunt;i++)
{
strBin .= (int) !empty($_POST['checkbox'][i]);
}
decVal = bindec(strBin);

 

Selektā arī var atselektēt visu ko vajag:

select ... where OPTS & 0x8

Edited by Delfins
Link to comment
Share on other sites

http://www.codingforums.com/showthread.php?t=81268 piemērs

 

 

<form action="" method="POST">
<table width="200" border="1">
 <tr>
<td width="75">Vertiba1</td>
<td width="109">

  <input type="checkbox" name="checkbox" value="1">
</td>
 </tr>
 <tr>
<td>Vertiba2</td>
<td><input type="checkbox" name="checkbox2" value="2"></td>
 </tr>
 <tr>
<td>Vertiba3</td>
<td><input type="checkbox" name="checkbox3" value="3"></td>
 </tr>
 <tr>
<td>Vertiba4</td>
<td><input type="checkbox" name="checkbox4" value="4"></td>
 </tr>
 <tr>
<td>Vertiba5</td>
<td><input type="checkbox" name="checkbox5" value="5"></td>
 </tr>
 <tr>
<td>Vertiba6</td>
<td><input type="checkbox" name="checkbox6" value="6"></td>
 </tr>
 <tr>
<td>Vertiba7</td>
<td><input type="checkbox" name="checkbox7" value="7"></td>
 </tr>
 <tr>
<td>Vertiba8</td>
<td><input type="checkbox" name="checkbox8" value="8"></td>
 </tr>
 <tr>
<td>Vertiba9</td>
<td><input type="checkbox" name="checkbox9" value="8"></td>
 </tr>
 <tr>
<td>Vertiba10</td>
<td><input type="checkbox" name="checkbox10" value="10"></td>
 </tr>
 <tr>
<td>Vertiba11</td>
<td><input type="checkbox" name="checkbox11" value="11"></td>
 </tr>
 <tr>
<td>Vertiba12</td>
<td><input type="checkbox" name="checkbox12" value="12"></td>
  </tr>
</table>
</form>

 

 

Ieķeksēto boxu vērtības jāsaskaita.

 

Un tāpēc jautāju, ko viņš grib darīt ar tiem čekbokšiem
naudu skaitīt... Edited by Zoom
Link to comment
Share on other sites

Stopp --> bezceriigi jo Zoom nezina kas tur ir lieks un kas nav.......

Zoom --> cekboksiem izmanto Onclick teksta laukiem Onchange

 

-------------------

/* This script is Copyright © Paul McFedries and

#16

Logophilia Limited (http://www.mcfedries.com/).

#17

Permission is granted to use this script as long as

#18

this Copyright notice remains in place.*/

Link to comment
Share on other sites

<script>
function skaitit() {
var skaits=0;
var checki=document.getElementsByName("c");
for(i=0;i<checki.length;i++) {
if (checki[i].checked==true) skaits+=1;
}
alert(skaits);
}
</script>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>
<input type="checkbox" name="c" onClick="skaitit()"/>

Link to comment
Share on other sites

<script language="javascript" type="text/javascript">
function Calculate (obj) {
ips=obj.parentNode.getElementsByTagName('INPUT');
sum=0;
for (i=0;i<ips.length;i++){
if (ips[i].checked){
sum+=ips[i].value*1;
}
}
document.getElementById('total').value=sum;
}
</script>
 <input name="prece" type="checkbox" id="prece" onClick="Calculate(this)" value="1"> 
 <input name="prece" type="checkbox" id="prece" onClick="Calculate(this)" value="2"> 
 <input id="total" size="5">

Link to comment
Share on other sites

×
×
  • Create New...