I'm having problem to update radio values. When I use a submit button to submit the form, it works fine, but when I use javascript, the values are not updated in database. And I'm using jquery mobile. Can anybody help? thanks!
UPDATED CODE, now only the first 3 radio buttons are working
dynamically generates 3 radio buttons for each task:
<?php
include 'connection.php';
$query = "SELECT*FROM plan";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$id=mysql_result($result, $i, "id");
$task=mysql_result($result, $i, "task");
$state=mysql_result($result, $i, "state");
?>
<form id="formnobtn" action="nobtn.php" method="POST" data-ajax="false">
<input type="hidden" name="id" value="<? echo "$id";?>">
<input type="radio" name="r" id="rA" value="A" class='custom' data-theme="a" <?php if ($statE == 'A'): ?>checked='checked'<?php endif; ?>><label for="rA"> </label>
<input type="radio" name="r" id="rB" value="B" class='custom' data-theme="c" <?php if ($statE == 'B'): ?>checked='checked'<?php endif; ?>><label for="rB"> </label>
<input type="radio" name="r" id="rC" value="C" class='custom' data-theme="f" <?php if ($statE == 'C'): ?>checked='checked'<?php endif; ?>><label for="rC"> </label>
<div data-role="collapsible" name="ud_c" value=" <?echo "$task";?> "><h3><?echo "$task";?></h3></div>
</form>
<?php
$i++;
}
?>
javascript which should submit the form on check of a radio button:
$(document).ready(function() {
$('input[type="radio"]').click(function(){
if ($(this).is(":checked"))
$('form#formnobtn').submit();
});
})
update database:
<?php
$id = $_POST['id'];
if (isset($_POST['r'])){
$state = $_POST['r'];
echo $state;
include 'connection.php';
$query= "UPDATE plan SET state='$state' WHERE id='$id'";
mysql_query($query);
mysql_close();
header('Location: nobtn.php');
}
?>