Reputation: 860
I haven't been able to find an answer to this that works. All I want to do is check with Jquery to see if something has been posted in PHP.
PHP:
if ($_POST['clockin'] == "Clock In") {
//some code
};
And for the Jquery:
if (<?php $_POST['clockin'] == "Clock In" ?>) {
$("#clockin").click(function(){
$(this).attr('disabled', 'disabled');
$("#clockout").removeAttr('disabled');
});
};
Upvotes: 0
Views: 911
Reputation: 11987
Try this,
<?php if ( isset($_POST['clockin'])) {
if ( $_POST['clockin'] == "Clock In") { ?>
$("#clockin").click(function(){
$(this).attr('disabled', 'disabled');
$("#clockout").removeAttr('disabled');
});
<?php } } ?>
Make sure you enclose script with <script></script>
tags.
Upvotes: 3
Reputation: 1580
You shouldn't mix Server and Client Code(JS) unless you have no option but you can embed php in html thats advantage of scripting If you want to check it on Page load if previous page was form submission
Use Flag to check whether clock in is set php
<?php
$flag=false;
if ($_POST['clockin'] == "Clock In") {
$flag=true;
}
?>
html
<html>
<body>
<form onsubmit="return changeAttr(<?php echo $flag ?>);">
<input type="submit" id="clockin" />
<input id="clockout" />
</form>
</body>
</html>
JS
function changeAttr(flag) {
//alert(flag);
var clckin = document.getElementById('clockin');
var clckout = document.getElementById('clockout');
if (flag) {
clckin.disabled = true;
clckout.disabled = false;
return false;
}
return true;
}
Upvotes: 0