jquery - Enable button until select fields will chosen -
i try make button enabled/disabled status until user choose 4 select boxes. based on solution: link here link in case can't make working. here fiddle: http://jsfiddle.net/ http://jsfiddle.net/marekandrzejak/nycz6/, wrong?
html:
<form action="classes/script.php" method="post" name="pricelist" style="float:left;"> <div class="price_list option"> <label for="choose_currency">wybierz walutę</label> <select id="choose_currency" name="choose_currency"> <option value="" selected="selected">wybierz...</option> <option value="1">pln</option> <option value="<? echo $obj->getgbprate() ?>">gbp</option> <option value="<? echo $obj->geteurrate() ?>">eur</option> <option value="<? echo $obj->getusdrate() ?>">usd</option> </select> </div> <div class="price_list option"> <label for="vat">podatek vat</label> <select id="vat" name="vat"> <option value="" selected="selected">wybierz...</option> <option value="23">23%</option> <option value="0">0% wdt</option> </select> </div> <div class="price_list option"> <label for="discount">rabat</label> <select id="discount" name="discount"> <option value="" selected="selected">wybierz...</option> <option value="0">0%</option> <option value="5">5%</option> <option value="10">10%</option> <option value="15">15%</option> <option value="20">20%</option> </select> </div> <div class="price_list option"> <label for="language">język</label> <select id="language" name="language"> <option value="" selected="selected">wybierz...</option> <option value="7">polski</option> <option value="1">angielski</option> </select> </div> <button class="button minibutton" id="pricelistbtn" type="submit" name="submit" value="pobierz"><span class="mini_icon mini_icon_zapisz"></span>pobierz</button>
script (in head):
$('#pricelistbtn').attr('disabled', 'disabled'); $(document).ready( function updateformenabled(){ if (verifyadsettings()) { $('#pricelistbtn').attr('disabled', ''); } else { $('#pricelistbtn').attr('disabled', 'disabled'); } function verifyadsettings() { if ($('#choose_currency').val() != '' && $('#vat').val() != '' && $('#discount').val() != '' && $('#language').val() != '') { return true; } else { return false; } } $('#choose_currency').change(updateformenabled); $('#vat').change(updateformenabled); $('#discount').change(updateformenabled); $('#language').change(updateformenabled); } );
please have @ http://jsfiddle.net/89pyb/
$('#pricelistbtn').attr('disabled', 'disabled'); function updateformenabled(){ if (verifyadsettings()) { $('#pricelistbtn').removeattr("disabled"); } else { $('#pricelistbtn').attr('disabled', 'disabled'); } } function verifyadsettings() { if ($("#choose_currency option:selected").val() != '' && $("#vat option:selected").val() != '' && $('#discount option:selected').val() != '' && $('#language option:selected').val() != '') { return true; } else { return false; } } $(document).ready(function(){ $('#choose_currency').change(updateformenabled); $('#vat').change(updateformenabled); $('#discount').change(updateformenabled); $('#language').change(updateformenabled); });
Comments
Post a Comment