Hi Guys,
I’m not sure if I can do this in php or javascript, but I have a problem.
When the user clicks on checkbox, the hidden div (calendar) shows up. However, after he submits and page reloads- due to an empty required field- the checkbox stays ticked but the calendar dissapears. Which I think is because javascript goes back to default stage. Although the box appears ticked, I have to untick and tick again for calendar to reshow.
Is there a way I can make the calendar show up once the page refreshes?
Any help appreciated,
Thank you.
<script type="text/javascript">
<!--
function showMe (it, box) {
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;
}
//-->
</script>
<form action="register-civ.php" method="post" name="go">
<input type="checkbox" name='c2' value="check me 2" onclick="showMe('div1', this)"
<?php echo $name_text = isset($_REQUEST['c2']) ? 'checked':'';?> /> Specific date<p/>
<div id="div1" style="display:none">
a calendar I have for the user
</div>
<input name="submit" value="Submit" type="submit" /></form>
I’m sorry but I don’t really understand your question StarLion.
The page reloads to self, so the "onclick=“showMe(‘div1’, this)”
" is still there, yes.
Thank you Zbing, I used your code and it obviously worked. And the default state of the calendar is always visible like you and Cups suggested.
As far as I understand: if mcb is not triggered than cal is not displayed, or else it’s ‘blocked’. What does ‘block’ mean. Does that mean ‘displayed’ in javascript?
And why can’t PHP do all this? Why do we need javascript?
I thought the whole idea of a programming language is that it’s all- encompassing, which means it should do as much as possible?!
Although you might frown or chuckle at my ignorance, would it be extremely difficult to allow PHP to verify state of checkboxes and show hidden divs?
function checkMyBox(trigger,toggled){
var mcb = document.getElementById(trigger);
var cal = document.getElementById(toggled);
if(mcb.checked == false){
cal.style.display = 'none'; } else {
cal.style.display = 'block'; } };