jquery - disable button until input and file fields have got value -
i have got form here:
<form action="#" method="post"> text: <input type="type" name="text" id="text" /><br /> file: <input type="file" name="fileinput" id="fileinput" /><br /> <select name="cars"> <option value="volvo">1</option> <option value="saab">2</option> <option value="mercedes">3</option> <option value="audi">4</option> </select><br /> <input type="submit" value="submit" disabled /> </form> <div id="result"></div>
and want disable submit button until fields(including dropdown) have been filled out or chosen.
my code is:
$(document).ready( function() { $('form > input').keyup && $('input:file').change(function() { var empty = false; $('form > input').each(function() { if ($(this).val() == '') { empty = true; } }); if (empty) { $('#submit').attr('disabled', 'disabled'); } else { $('#submit').removeattr('disabled'); } }); }; function(){ $('input:file').change( function(){ if ($(this).val()) { $('input:submit').attr('disabled',false); } } ); });
please activate button when input got text, dropdown has got value , input type got file selected.
my fiddle here: http://jsfiddle.net/e42xa/214/
thank you.
$("form > *").change(function() { var fields = $("form input, form select").not("input[type='submit']"); var filledfields = fields.filter(function() { return $(this).val().length > 0; }); if (filledfields.length == fields.length) { $("input[type='submit']").removeattr("disabled"); } else { $("input[type='submit']").attr("disabled", "disabled"); } });
Comments
Post a Comment