PDA

Просмотр полной версии : В ходе написания скрипта, возникла проболема...


Micr0b
11.11.2009, 21:03
Привет.
В ходе написания скрипта, возникла проболема.
Хочу отправить через пост-форму значения с активным атрибутом checked, но так чтоб button была поза пост-формой.
пробовал реализировать, вот мой не доделаный пример:
<script src="../../js/jquery-1.3.2.js" type="text/javascript"></script>

<script>
function button(){
//alert($('#form input').attr('value'));
if($('#c').is(':checked')){
alert($('#c').val());
$("#c").attr("checked","");
}else{
alert('Пожалуйста, выберите из списка для выключить');
}
}
</script>
<input type="button" onclick="button();" value="Выключить"><br><br>
<form method="post" id="form">
<input type="checkbox" checked name="" id="c" value="1">
<input type="checkbox" checked name="" id="c" value="2">
</form>
Здесь реализировано мой пример на пхп:
<form method="post">
<input type="checkbox" checked name="allbox[]" value="1">
<input type="checkbox" checked name="allbox[]" value="2">
<input type="submit" name="submit">
</form>
<?
if($_POST['submit'])
{
if(!$_POST['allbox']==""){
foreach($_POST['allbox'] as $key){
echo $key;
}
}
}
?>

diGriz
11.11.2009, 22:43
Попробуй так:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script>
function button(){
if($('#1c').is(':checked') || $('#2c').is(':checked')){
//alert($('.c').val());
//$("#2c").attr("checked","");
return true;
}else{
alert('Пожалуйста, выберите из списка для выключить');
return false;
}
}
</script>

<form method="post" id="form" action="test.php" onsubmit="return button(this);">

<input type="checkbox" checked name="allbox[]" id="1c" value="1">
<input type="checkbox" checked name="allbox[]" id="2c" value="2">
<input type="submit" name="submit" value="Выключить" id="on"><br><br>
</form>
<?php
if($_POST['submit'])
{
if(!$_POST['allbox']==""){
foreach($_POST['allbox'] as $key){
echo $key;
}
}
}
?>