I have a form that has a input field type "file" to upload an image.
<input type="file" name="dpimg" id="dpimg">
To this I need to attach a file via Javascript on the click of a checkbox button placed near the field.
<input type="checkbox" onclick="dpChecked()" id="dp-check">
When the checkbox is ticked the image has to be attached to input field "#dpimg".
function dpChecked() {
var checkBox = document.getElementById("dp-check");
if (checkBox.checked == true) {
//Attach image to #dpimg
} else {
//Remove image to #dpimg
}
}
Is this possible? If not, are there any alternatives?
Reason why I want this
It is a temporary fix to validate a form.
The form in question has many fields and the validation part is built in a rigid way. Making certain fields optional is going to take a while and so for the time being I need a way I can attach an image that will validate the form.
The intended purpose of the "#dp-check" checkbox is to make the field optional.