I've a silly problem.
Depending on a the visibility of a div I want to set a hidden value
if($('#crewMember').is(':visible')) {
$('#visibility').attr('value', 'hidden')
} else {
$('#visibility').attr('value', 'visible')
}
This works. I've checked it via FireBug and I can see that the HTML has changed.
But when I try to get this value after form submission I get the original value, not the changed value.
echo $_POST['visibility']
//returns default value, not the adjusted valueHow come?
How come?
EDIT SOme example code
<html>
<script type="text/javascript">
$(document).ready(function() {
$('#div').click(function() {
$('#visibility').val('hidden');
$('#value').html('hidden value: ' + $('#visibility').val());
});
$('#value').html('hidden value: ' + $('#visibility').val());
});
<body>
<form method="post">
<div id="div">
click this area to change value
</div>
<div id="value"> <!-- This div will show the actual value of the hidden field -->
</div>
<input type="hidden" id="visibility" name="visibility" value="initial value" />
<input type="submit" name="button" value="button" />
</form>
</body>
</html>
When I submit this form the $_POST['visibility'] always contains the string 'initial value'. Even when I changed the value with JS to 'hidden';