I am trying to show a div which contains an input for file upload, the rule that I need to comply with is to show div it only if the status is equal to 1, otherwise it will hide it.
I have the status declared in a PHP variable called $status, to hide the div I use the display='none'.
The following is the validation code that I use in a Javascript function.
function showFileInput (){
var element = document.getElementById('content');
if ($status == '1'){
element.style.display='block';
}else{
element.style.display='none';
}
}
In my HTML code I have the following div that I want to display when the status is equal to 1.
<div id="content" class="form-group row">
<label for="fileToUpload" class="col-sm-3 col-form-label">File Upload:</label>
<div class="col-sm-8">
<input type="file" name="fileToUpload" id="XmlToUpload" class="btn" accept=".xml" onchange="ValidateFile()" required="">
</div>
</div>
It's important to note that I make use of the event onchange for other additional validations that I use when uploading the file.
With what I have previously, the div is still not hidden when the status is different from 1, it continues to be shown. Is there something that I am doing wrong in my validation or do I need additional?
showFileInput()? The HTML callsValidateFile().ValidateFile()function. this kinda seems like you are tryting to use php variable which is not evaluated at a time you print the page, in other words only after the file submit you have the php variable with relevant data (or as ajax result but then code would look differently)echoout that div if the variable doesn't have the correct value. If you want it to show or hide depending on user interactions without reloading the page, then you need JS, but it's not clear what your requirements are in that case.