嘿我正在检查是否选中了复选框,然后检查是否已将该数据拉入我表单中的隐藏字段作为我要发布的表单的值。这是我正在使用的。
### Update User Profile
if (@$_POST['savePrivacy']) {
// error checking
// update user
if (!$errorsAndAlerts) {
$colsToValues = array();
$colsToValues['show_contact'] = $_REQUEST['show_contact'];
$colsToValues['test'] = $_REQUEST['test'];
// ... add more form fields here by copying the above line!
$colsToValues['updatedByUserNum'] = $CURRENT_USER['num'];
$colsToValues['updatedDate='] = 'NOW()';
mysql_update(accountsTable(), $CURRENT_USER['num'], null, $colsToValues);
// on success
$errorsAndAlerts = "Thanks, we've updated your privacy settings!<br/>\n";
redirectBrowserToURL('edit-profile.php');
}
}
<form method="post" role="form" action="">
<input type="hidden"name="savePrivacy" value="1" />
<div class="checkbox">
<span class="checked">
<label>
<input type="checkbox" id="view"> Yes</label>
<input type="hidden" name="show_contact" value="0">
<script>
var state = window.jQuery("#view").prop("checked") ? 1 : 0;
$('input[name="show_contact"]').val(state);
</script>
</span>
</div>
<input class="button btn green-haze" type="submit" name="submit" value="Save" />
</form>
我想将已检查状态的值拉入隐藏值。非常感谢帮助!
答案 0 :(得分:0)
请试试这个,
var state = window.jQuery("#view").is(":checked") ? 1 : 0;
$('input[name="show_contact"]').val(state);