how to manage in JavaScript null values from PHP code -
i have next php/html code upload image:
<label>image (*)</label> <!-- if image exists, show --> <?php if($category->getimage() === null) : ?> <input type="file" name="image" id="image" required> <?php else : ?> <p><img src="../uploads/images/<?php echo $categoria->getimage(); ?>"></p> <input type="file" name="image" id="image"> <?php endif; ?>
and want validate using javascript
// validate image image = document.getelementbyid("image").value; if (!image) { window.alert("you must select file image."); document.getelementbyid("image").focus(); return false; }
the image required. if create new registry sets of atributes null, including image. then, image not show , can set in form. if want update them, form shows current imagen don't have update if don't want to.
i need validate if file hasn't been uploaded , value null means user creating new registry , image required. if file hasn't been uploaded value isn't null, user updating registry , isn't required upload image.
thanks in advance , sorry bad english.
you can add id image
<img id="foo" src="../uploads/images/<?php echo $categoria->getimage(); ?>">
and check if it's in dom:
if ($('#foo').length) { // image there }
or without jquery:
if (document.getelementbyid("foo")) { // image there }
Comments
Post a Comment