Jump to content
php.lv forumi

Skaitlošana


Settlers

Recommended Posts

Piemeeram shim koodam

http://javascript.internet.com/forms/order-form.html

gribu pievienot klaat izveeli ar cenaam.......

 

<select name="select" size="1">
														<option value="1">1 $</option>
														<option value="2">2 $</option>
														<option value="3">3 $</option>
														<option value="4">4 $</option>
  </select>

 

un protams vinjs visu saskaita kopaa.... Bet nezinu kā lai to izdaru :| Kaads var izpaliidzeet ?

 

oi ieliku nepareizajaa sadaljhaa! Cerams ka moderaatori paarliks uz JavaScript, VBScript

Link to comment
Share on other sites

kaut kā tā..

 

var Totals = tavaForma.select.options[tavaForma.select..selectedIndex].value;

 

iizsti nesapratu tavu domu :( vari precizet ar skaitljiem ?

 

piemeeram kad ieksjheksee ir shaads

 

<input type="checkbox" name="Chicken" value=12.00 onClick="this.form.total.value=calculateTotal(this);">

 

un tad vinjs automaatiski tur saskaitiis klaat tos 12.00 summu

 

bet kaa lai to izdaru uz izveeli

 

<select name="izveele">
  <option selected="selected"></option>
  <option>100</option>
  <option>200</option>
</select>

 

iizsti nezinu kur lai lieku to Value un ...............this.form.total.value=calculateTotal(this);.......................

Link to comment
Share on other sites

es nezinu, vai javaskriptā var visu laiku editēt vienu variabli, lai viņš saglabājas, līdz lapa tiek pārlādēta, bet ar cepumiem var mierīgi to darīt..

 

<input type="checkbox" value="12" onclick="[uztaisam kūkija value=kūkija tagadējais value+this.value"/>

 

nu kaut kā tā, ja es tevi pareizi sapratu un ja tu mani sapratīsi ;)

Link to comment
Share on other sites

man straadaa uz cjkekshiem bet es gribu to uzlitk uz

 

<select name="izveele">
  <option selected="selected"></option>
  <option>100 $</option>
  <option>200 $</option>
</select>

 

izveeles formai...... tipa ka izveelies piemeeram tos 100 un vinjs pieskaita beigaas tos 100 ja izveelaas 200 tad pieskaitiis 200 nevis 100.....

Link to comment
Share on other sites

Nju tagad man ir cita probl!

 

http://www.settlers.colt.lv/test/1.php

 

Un es uzlik ushaadi:

 

<select name="name" onChange="this.form.total.value=calculateTotal(this);" style="WIDTH: 257px">
  <option selected="selected" value=0.00>Izveelies</option>
  <option value=50.00>50 - 100</option>
  <option value=100.00>100 - 200</option>
</select>

 

bet tagad man vinjs tur visu laiku saskaita ja paartinju izveeli .....

 

piemeeram:

izveelos 50 (pieskaita apakshaa 50) un peeksnji paardomaaju uzlikt uz 100 (tad apakshaa pieskaita +100 ( jau iznaak 150)) bet mana nevajag ka vinjs tur beigaas uzraadiis ljoti lielulu skaitli ja kaads visu laiku paardomaas un uzliks citu izveeli.....

 

kur vareetu buutu probleema?

Link to comment
Share on other sites

Droši vien vajag kādā variablī saglabāt, cik tu ar konkrēto selectu esi pēdējo reizi pieskaitījis, un ja izvēlies citu vērtību, papriekš atskaitīt veco, un tad skaitīt klāt jauno, protams, atkal saglabājot variablī to vērtību... Imho, vienkāršāk uzlikt buttonu 'Calculate total' uz kuru nospiežot tad viss tiek sarēķināts...

Link to comment
Share on other sites

nu kā rekāds ir scripts pats:

 

<script LANGUAGE="JavaScript">
<!-- hide javascript from non-JavaScript browsers.
	// This function calculates the total for items in the form which are selected
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);	
		}
		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.previouslySelectedRadioButton.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;
		}
	}

}

// end commenting javascript -->
</SCRIPT>

 

cik es pamaniiju ka tev dod atljau kur ir apliishi izveeleeties 1 no 4 ir shaads tipa scripts

 

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);	
		}
		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);	
		}

 

bet kaal ia paarveidoju uz select jeb sho lai straadaatu:

 

<select name="name" onChange="this.form.total.value=calculateTotal(this);" style="WIDTH: 257px">
  <option selected="selected" value=0.00>Izveelies</option>
  <option value=50.00>50 - 100</option>
  <option value=100.00>100 - 200</option>
</select>

 

teikshu ka neesu spec Java scriptos! :)

 

Cik googlee atradu shaadu saitu

 

https://www.atlassian.com/software/Buy.jspa...?purchaseList=0

Link to comment
Share on other sites

Nav skairs, kāpēc tev tur divreiz atkārtojas viens un tas pats koda gabals:

if (inputItem.type == "radio") {...}

Manā saprašanā, uz ātru skatu, vajag tik vienreiz, to if(..) {...}else {...}

Un tanī pašā pieliec ko tādu:

else if (inputItem.type == "select") {...}

Un pašā radio apstrādes gabalā tas algoritms, ko tev vajag, jau ir. caur šito mainīgo: previouslySelectedRadioButton

Ieved tādu pašu priekš selecta, un uz priekšu...

Link to comment
Share on other sites

njaa tagad man nestraada 1 aile bet 2 aile ir ok

 

es izmantotju shaadu java script kodu

 

if (inputItem.type == "radio2") { // 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);	
		}

					if (inputItem.type == "radio3") { // 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);	
		}

 

un pashaa izveelem ir shaadi

 

<select type="radio2" name="select" onChange="this.form.total.value=calculateTotal(this);" style="WIDTH: 257px">

<option selected="selected" value=0.00>Izveelies2</option>

<option value=50.00>50</option>

<option value=100.00>100</option>

</select>

</font>

<select type="radio3" name="select" onChange="this.form.total.value=calculateTotal(this);" style="WIDTH: 257px">

<option selected="selected" value=0.00>Izveelies</option>

<option value=500.00>500</option>

<option value=1000.00>1000</option>

</select>

 

pirmajai iale kad maina jautaajumu nezkapeec dubultojaas un skaita klaat visu laiku :(

Link to comment
Share on other sites

×
×
  • Create New...