javascript - Add another condition to Show/Hide Divs -
i have follow script on form.
jquery(document).ready(function($) { $('#bizloctype').on('change',function() { $('#packages div').show().not(".package-" + this.value).hide(); }); }); </script>
basically, depending on value of select box #bizloctype
(value="1","2","3" or "4") corresponding div shows , rest hidden (div class="package-1","package-2","package-3", or "package-4"). works perfectly.
but, need add additional condition. need text box #annualsales
condition determining div shows (if value less 35000 should show package-1 only, , no other packages.
i think below script works fine when independent of other script need find out how marry them.
<script> $("#annualsales").change(function(){ $(".package-1,.package-2,.package-3,.package-4").hide(); var myvalue = $(this).val(); if(myvalue <= 35000){ $(".package-1").show(); } else { $(".package-2").show(); } }); </script>
help please?
i remove logic anonymous functions , this:
// handle display function displaypackage( fieldid ) { var packagetype = getpackagetype(fieldid); $('#packages div').show().not(".package-" + packagetype).hide(); } // getting correct value (1,2,3 or 4) function getpackagetype( fieldid ) { // default displayed type var v = 1; switch(fieldid) { case 'bizloctype': // first check annualsales 1 v = (getpackagetype('annualsales') == 1) ? 1 : $('#' + fieldid).val(); break; case 'annualsales': v = (parseint($('#' + fieldid).val(),10) <= 35000) ? 1 : 2; break; } return v; } jquery(document).ready(function($) { $('#bizloctype,#annualsales').on('change',function() { displaypackage($(this).attr('id')); }); });
Comments
Post a Comment