javascript - Hide input empty input upon Submit -
i trying hide empty fields upon submit $_get.
my code looks it's not working. logic of great.
<script> $(submit).click(function(){ if(input.value.length == 0) input.style.visibility = "hidden"; }); </script> edit: here button submits form -
<input name="savebtn" type="submit" id="savebtn" formaction="update1profile.php?id="<?php echo htmlentities($_server["php_self"]) ?> <?php echo $_get['source_id'] ?>" formmethod="get" value="save">
well code giving errors in browser console; it's idea check there first.
you need find <input> elements, , mentioning word "input" won't that. same goes "submit" element, whatever is. might like:
$('form').submit(function() { $(this).find('input').filter(function() { return this.value == ''; }).css('visibility', 'hidden'); }); edit — in comment below, op mentions wants avoid having empty inputs submitted. if that's case, making them invisible not that. instead (or additionally), it's necessary mark fields "disabled":
$('form').submit(function() { $(this).find('input') .filter(function() { return this.value == ''; }) .prop('disabled', true) .css('visibility', 'hidden'); });
Comments
Post a Comment