samedi 1 septembre 2018

Checkbox with PHP not disable onclick

Really simple question.

I have a checkbox / well actually multiple but i just wish for 1 checkbox to be able to click on off, But the catch is i have a POST sending a PHP variable to decide if the box is checked on load.. But the method i have use wont allow me to uncheck the box as IF $VAR="YES" CHECKBOX = CHECKED so my jscript will not uncheck it..

not sure if my explanation reveals the problem so im hoping the code will do.

If any1 can see a simple way around this id be greatfull, i just want a chreckbox that is checked if the POST is sent and not checked if i click it..

thank you.

<input  type="checkbox" id="withvideo" name="withvideo" class='Mcheckbox'  value="withvideo" <?php if ($hasvideo==='yes'):  ?> checked="checked" <?php endif; ?> onclick="chbxhas(this); <?php $hasvideo==='yes'; ?>">
</input>

<label for="withvideo" class="checkboxes" title='Show Items With Videos'>With Video</label><i class="fa fa-video plusclass" ></i>


<---receiving page--->

if (isset($_POST['withvideo'])){$hasvideo="yes";}

else {$hasvideo="no";}


<---jscript--->
<script>
function chbxhas(objhas)
{
var that = objhas;

(objhas);

if(document.getElementById(that.id).checked === true) {

document.getElementById('withvideo').checked = false;


}
document.getElementById(that.id).checked = true;
}
</script>




Aucun commentaire:

Enregistrer un commentaire