Ceviz Forum

Geri Dön   Ceviz Forum > Programlama > Javascript / DHTML / Ajax

Cevapla
 
LinkBack Seçenekler
Eski 19/04/2007, 10:04   #1 (permalink)
Üye
 
Üyelik Tarihi: 04/2007
Mesaj: 1
Soru checkbox ta seçeneklerin konrol etme

Arkadaşlar söyle bir sorunum var aşağıda javascriipt kodunu koydun js den pek anlamam yardım ederseniz çok sevinirim. Sorun şu kullanıcı aşağıdaki seçenekleri işaretleyecek ve ben her checkbox a value olarak farklı bir değer vermem gerekiyor. Ve kullanıcı sadece 40 value değeri aşmaması gerekli yani 40 işaretlemeler 40 ı geçerse uyarılması gerekli ,

checkbox'a farklı değerler vererek bir örnek js de işimi görürü. şimdiden çok teşekürler....



<script type="text/javascript" >
function calculateTotal(inputItem) {
with (inputItem.form) {
// Process each of the different input types in the form.
if (inputItem.type == "radio") { // Process radio buttons.
// Subtract the previously selected radio button value from the total.
calculatedTotal.value = eval(calculatedTotal.value) - eval(previouslySelectedRadioButton.value);
// Save the current radio selection value.
previouslySelectedRadioButton.value = eval(inputItem.value);
// Add the current radio button selection value to the total.
calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
} else { // Process check boxes.
if (inputItem.checked == false) { // Item was uncheck. Subtract item value from total.
calculatedTotal.value = eval(calculatedTotal.value) - eval(inputItem.value);
} else { // Item was checked. Add the item value to the total.
calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
}
}
// Total value should never be less than 0.
if (calculatedTotal.value < 0) {
InitForm();
}
// Return total value.
return(formatCurrency(calculatedTotal.value));
}
}
// Format a value as currency.
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '' + num + '.' + cents);
}
// This function initialzes all the form elements to default values.
function InitForm() {
// Reset values on form.
document.selectionForm.total.value='0';
document.selectionForm.calculatedTotal.value=0;
document.selectionForm.previouslySelectedRadioButt on.value=0;
// Set all checkboxes and radio buttons on form to unchecked.
for (i=0; i < document.selectionForm.elements.length; i++) {
if (document.selectionForm.elements[i].type == 'checkbox' | document.selectionForm.elements[i].type == 'radio') {
document.selectionForm.elements[i].checked = false;
}
}
}
</script>
<body onload="InitForm();" onreset="InitForm();">
<div align="center">
<table><tr><td>
<form method="POST" name="selectionForm">
Seçenek A<input type="checkbox" name="Steak" value="10.00" onclick="this.form.total.value=calculateTotal(this );">
Seçenek B
<input type="checkbox" name="Chicken" value="15.00" onclick="this.form.total.value=calculateTotal(this );">
Seçenek C
<input type="checkbox" name="Sushi" value="10.00" onclick="this.form.total.value=calculateTotal(this );">
Seçenek D
<input type="checkbox" name="Sushi" value="10.00" onclick="this.form.total.value=calculateTotal(this );">
Seçenek E
<input type="checkbox" name="Sushi" value="15.00" onclick="this.form.total.value=calculateTotal(this );">
Seçenek F
<input type="checkbox" name="Sushi" value="15.00" onclick="this.form.total.value=calculateTotal(this );">
<br><br>
<br>
<br>
<input type="hidden" name="calculatedTotal" value="0">
<input type="hidden" name="previouslySelectedRadioButton" value="0">
<strong>toplam</strong>
<input type="text" name="total" readonly onfocus="this.blur();">
</form>
</td></tr></table>
</div>
<p><p>
filozofca hatta değil   Alıntı Yaparak Yanıtla
Eski 16/05/2007, 02:06   #2 (permalink)
Üye
 
Üyelik Tarihi: 05/2007
Mesaj: 26
Varsayılan

PHP Kodu:
<script type="text/javascript">

function 
check(){
var 
document.getElementById('toplam');
var 
toplam 0;
var 
dizi = [], eli0;
while(
el document.getElementsByName('onay')[i++]){
if(
el.checked) {  toplam toplam Number(el.value);  }
}
t.value toplam;
if(
toplam 40 ) { alert("Toplam = " toplam " oldu. Yani 40 tan büyük."); }
}
</script>

<input type="checkbox" name="onay" value="5" onclick="check()">5<br>
<input type="checkbox" name="onay" value="10" onclick="check()">10<br>
<input type="checkbox" name="onay" value="15" onclick="check()">15<br>
<input type="checkbox" name="onay" value="20" onclick="check()">20<br>
<input type="checkbox" name="onay" value="25" onclick="check()">25<br><br>

Toplam<input type="text" id="toplam"><br> 
ayşe2 hatta değil   Alıntı Yaparak Yanıtla
Eski 24/02/2008, 02:30   #3 (permalink)
Üye
 
Üyelik Tarihi: 05/2007
Mesaj: 23
Varsayılan

mükkemmel ve bir o kadar kısa bir cevap tebrik ederim ayşe2.
turkman hatta değil   Alıntı Yaparak Yanıtla
Cevapla

Bookmarks

Seçenekler

Mesaj Yazma Hakları
Yeni mesajgöndermezsiniz
Cevap yazamazsınız
Dosya ekleyemezsiniz
Mesajınızı düzenleyemezsiniz

BB code is Açık
[IMG] kodu Açık
HTML kodu Kapalı
Trackbacks are Açık
Pingbacks are Açık
Refbacks are Açık

Benzer Konular
Konu Konuyu açana göre Forum Cevap En Son Mesaj
checkbox ilkbahar PHP 2 14/04/2007 00:17
asp checkbox darkface ASP 1 05/04/2007 10:27
checkbox biri işaretlenince altdaki değer checkbox otomatik checked olsun militaN Javascript / DHTML / Ajax 1 02/04/2007 14:37
checkbox ile seçilmiş bilgileri database'ye kayıt etme ercems ASP 3 05/06/2005 21:15
checkbox KanKi PHP 5 26/10/2004 11:35


Forum saati Türkiye saatine göredir. GMT +3. Şu anda saat 00:21.

Reklamlar & Desteklenenler
Hassas Valf | Hassas Kaplama | Antalyamız | Gazete | Ticari Bilişim | Hakan Müştak | Rüya Tabirleri | Kadın | Hastalıklar | Cepte msn ve e-posta | Webmaster | Antalya Aupair | Turkish Property Antalya | Forum | Chat | Perde | Adsl | Araba | bolindir.com | guncelle.com | livescore | Web Tasarım | evden eve nakliyat | forum | evden eve | sohbet | Resimcim| Kalifiye İnsan Kaynakları | Web Tasarım | Oyun | Yusuf KOÇ | Akın Yorulmaz | şiir | UFO | Web Tasarım | Oyunlar | Canlı Tv |


Forum Yazılımı: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright ©2001 - 2008, Ceviz.net