What I want to do is: When each button is pressed, show it's respective value. Right now the value returned is always "1". The json.php file will eventually be used to update records in a database.
Any help would be greatly appreciated. Thanks!
Here's the json.php file:
<?php
if(isset($_POST['hidden'])) {
$data['value'] = $_POST['hidden'];
}
echo json_encode($data);
?>
And here's the HTML:
<html>
<head>
<title>jQuery/Ajax - Display respective values on submit for inputs with same class name</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("form[name=form1]").submit(function() {
$.post("json.php", { hidden : $(".check").siblings(".hidden").val() },
function(data){
alert(data.value);
}, "json");
return false;
});
});
</script>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" name="form1" method="post">
<input type="submit" class="check" value="check1" /><br />
<input type="submit" class="check" value="check2" /><br />
<input type="submit" class="check" value="check3" />
<input class="hidden" name="hidden" type="hidden" value="1" />
<input class="hidden" name="hidden" type="hidden" value="2" />
<input class="hidden" name="hidden" type="hidden" value="3" />
</form>
</body>
</html>