user2431727
user2431727

Reputation: 907

How to display a div which is else part of php code

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

Answers (2)

Saili Jaguste
Saili Jaguste

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

imprezzeb
imprezzeb

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

Related Questions