Reputation: 907
I have a div "BrowseDiv" which is in else part of php code as shown below. if $url is not exists, it should show the div. Also When check the check box , I'm calling a java script which should display the div.But it is not displaying when onchange checkbox is calling
<tr height="20px" >
<td style="text-align:center">
<?php if(file_exists($url)){ ?>
<a href=<?php echo "documents/".$num."/".$id;?> target="_blank" id="href_doc1">My Doc</a>
</br>
<input type="checkbox" id="check_doc1" name="check_doc1" onchange="CheckedDelete('check_doc1')">Delete My Doc</input>
<?php } else { ?>
</br></br>
<div id="BrowseDiv" ><b></br>Upload Supporting Document</b> </br>
<input type="file" name="doc1_upload_onload" id="doc1_upload_onload">
</div>
} ?>
</td>
</tr>
function CheckedDelete(chk_bx){
if (document.getElementById(chk_bx).checked == true) {
alert(" will be deleted");
var href_doc1 = document.getElementById('href_doc1');
href_doc1.style.display = 'none';
document.getElementById('BrowseDiv').style.display= 'block';
} else {
var Thephoto = document.getElementById('href_doc');
Thephoto.style.display = 'block';
document.getElementById('BrowseDiv').style.display= 'none';
}
}
Upvotes: 0
Views: 61
Reputation: 126
The "BrowseDiv" is in else part and hence document.getElementById('BrowseDiv') must be returning NULL.
For this you need to change your logic a bit. Something like this:
<td style="text-align:center"><?php if(file_exists($url)){ ?>
<a href=<?php echo "documents/".$num."/".$id;?> target="_blank" id="href_doc1">My Doc</a>
</br>
<input type="checkbox" id="check_doc1" name="check_doc1" onchange="CheckedDelete('check_doc1')">Delete My Doc</input>
<?php } ?>
</br></br>
<div id="BrowseDiv" style="display: <?php echo (file_exists($url)) ? 'none' : 'block' ?>" ><b></br>Upload Supporting Document</b> </br>
<input type="file" name="doc1_upload_onload" id="doc1_upload_onload">
</div>
Upvotes: 1
Reputation: 716
You should do this instead..
<tr height="20px" >
<td style="text-align:center"><?php if(file_exists($url)){ ?>
<a href=<?php echo "documents/".$num."/".$id;?> target="_blank" id="href_doc1">My Doc</a>
</br>
<input type="checkbox" id="check_doc1" name="check_doc1" onchange="CheckedDelete('check_doc1')">Delete My Doc</input>
<?php } ?>
</br></br>
<div id="BrowseDiv" style="display: <?php if(file_exists($url) { echo 'none'; } else { echo 'block'; } ?>"><b></br>Upload Supporting Document</b> </br>
<input type="file" name="doc1_upload_onload" id="doc1_upload_onload">
</div>
</td>
</tr>
Upvotes: 1