...
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#ajax_form").on("submit", function(){
var data = [];
$("#ajax_form input[type='checkbox']:checked").each(function(){
data.push({value: $(this).val(), text: $("label[for="+$(this).attr("id")+"]").text()});
});
$.ajax({
type: "POST",
url: "test.php?do_action=some_action3",
data: {chk1: data},
success: function(sum){
alert("Сумма - "+sum);
}
});
return false;
});
});
</script>
</head>
...
<main>
<section>
<form method="post" action="">
<input type="hidden" name="do_action" value="some_action" />
<label for="house"><input type="checkbox" name="chk1[Дом]" id="house" value="4000000" />Дом</label>
<label for="avto"><input type="checkbox" name="chk1[Авто]" id="avto" value="1000000" />Авто</label>
<label for="phone"><input type="checkbox" name="chk1[Телефон]" id="phone" value="25000" />Телефон</label>
<button type="submit">go! go! go!</button>
</form>
</section>
<p> или например так:</p>
<section>
<form method="post" action="">
<input type="hidden" name="do_action" value="some_action2" />
<label for="house2"><input type="checkbox" name="chk1[0]" id="house2" value="4000000" />Дом</label>
<input type="hidden" name="chk1_value[0]" value="Дом" />
<label for="avto2"><input type="checkbox" name="chk1[1]" id="avto2" value="1000000" />Авто</label>
<input type="hidden" name="chk1_value[1]" value="Авто" />
<label for="phone2"><input type="checkbox" name="chk1[2]" id="phone2" value="25000" />Телефон</label>
<input type="hidden" name="chk1_value[2]" value="Телефон" />
<button type="submit">go! go! go!</button>
</form>
</section>
<p>ну или с AJAX, вот так:</p>
<section>
<form method="post" action="" id="ajax_form">
<input type="hidden" name="do_action" value="some_action3" />
<label for="house3"><input type="checkbox" name="chk1[]" id="house3" value="4000000" />Дом</label>
<label for="avto3"><input type="checkbox" name="chk1[]" id="avto3" value="1000000" />Авто</label>
<label for="phone3"><input type="checkbox" name="chk1[]" id="phone3" value="25000" />Телефон</label>
<button type="submit">go! go! go!</button>
</form>
</section>
</main>
if (isset($_REQUEST['do_action'])) {
switch ($_REQUEST['do_action']) {
case 'some_action':
foreach ($_REQUEST['chk1'] as $k => $v) {
echo $k.' - '.$v.'<br />';
}
$sum = array_sum($_REQUEST['chk1']);
echo '<br />Сумма - '.$sum;
break;
case 'some_action2':
foreach ($_REQUEST['chk1'] as $k => $v) {
echo $_REQUEST['chk1_value'][$k].' - '.$v.'<br />';
}
$sum = array_sum($_REQUEST['chk1']);
echo '<br />Сумма - '.$sum;
break;
case 'some_action3':
$sum = 0;
for ($i = 0; $i < count($_REQUEST['chk1']); $i++) {
//echo $_REQUEST['chk1'][$i]['text']; // do something with text here!
$sum += $_REQUEST['chk1'][$i]['value'];
}
echo $sum;
exit();
break;
}
}
<select>
всё чуток по другому (google it -> "html select get selected value"):$("#my_select").change(function() {
var e = document.getElementById("my_select");
var razmer = e.options[e.selectedIndex].value;
$("h3").text(razmer);
}
);
function addEvent(e, type, handler) {
if (e.addEventListener) {
e.addEventListener(type, handler, false)
} else {
e.attachEvent("on"+type, handler)
}
}
var select = document.getElementById("my_select");
addEvent(select, "change", function() {
var razmer = this.options[this.selectedIndex].value;
document.getElementsByTagName("h3")[0].innerHTML = razmer;
});