Hailstone Posted July 13, 2015 Share Posted July 13, 2015 Hi.. i have this project hotel booking.. if the person select a room 2 dropdown appears "adult" and "child" the max adult is 2.. if somebody please can help me.. child option dropdown must only enabled if the first dropdown value is 2.. my problem is if you select more than 1 room the first 2 dropdown works and the following dropdown doesn't work (the loop rooms). <select name="adults[]" class="hbSelect hbSelectorPeople" data-index="<?php echo $j; ?>"> <?php foreach (range(1, $tpl['room_arr']['adults']) as $i) { $selected = ( isset($STORE['all_rooms'][$_GET['room_id']][$j]) && $STORE['all_rooms'][$_GET['room_id']][$j]['adults'] == $i ); ?><option value="<?php echo $i; ?>"<?php echo !$selected ? NULL : ' selected="selected"'; ?>><?php echo $i; ?></option><?php } ?> </select> </td> <td class="hbBorderBottom"> <select name="children[]" class="hbSelect hbSelectorPeople" data-index="<?php echo $j; ?>"> <?php foreach (range(0, $tpl['room_arr']['children']) as $i) { $selected = ( isset($STORE['all_rooms'][$_GET['room_id']][$j]) && $STORE['all_rooms'][$_GET['room_id']][$j]['children'] == $i ); ?><option value="<?php echo $i; ?>"<?php echo !$selected ? NULL : ' selected="selected"'; ?>><?php echo $i; ?></option><?php } ?> </select> Can someone help me make a validation in a looping script to enable only the 2nd dropdown if first dropdown value is 2. Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/ Share on other sites More sharing options...
fastsol Posted July 13, 2015 Share Posted July 13, 2015 You're lack of punctuation in your post is making this hard to understand what you're trying to do. If you are trying to enable/disable the dropdown only when another dropdown is selected, but do it without refreshing the page, you'll need to use javascript. Otherwise the other dropdown will only be able to be enabled by php if the page is refreshed. Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/#findComment-1516211 Share on other sites More sharing options...
scootstah Posted July 13, 2015 Share Posted July 13, 2015 Here's an example using jQuery: http://jsfiddle.net/9vsoqs5t/ Room for improvement, but that should get you started. Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/#findComment-1516226 Share on other sites More sharing options...
Hailstone Posted July 14, 2015 Author Share Posted July 14, 2015 I LOVE YOU!.. thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/#findComment-1516290 Share on other sites More sharing options...
Hailstone Posted July 14, 2015 Author Share Posted July 14, 2015 Got a problem.. if only 1 selection the Book/Go button doesn't work.. Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/#findComment-1516291 Share on other sites More sharing options...
scootstah Posted July 14, 2015 Share Posted July 14, 2015 Can you post your new code please. Also, please use the code tags when you do. Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/#findComment-1516316 Share on other sites More sharing options...
Hailstone Posted July 15, 2015 Author Share Posted July 15, 2015 The Submit button is working.. just got one problem.. when i choose person more than 1 + extra person the price does not change.. the price stuck for 1 person only. The javascript $(function(){ $('select[name^=adults]').on('change', function(){ var childName = $(this).prop('name').replace(/adults/, 'children'); var childEl = $('select[name="' + childName + '"]'); if ($(this).val() == 2) { childEl.prop('disabled', false); } else { childEl.prop('disabled', true); childEl.val(0); } }); }); and the php script <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" name="room_id" value="<?php echo $tpl['room_arr']['id']; ?>" /> <table cellpadding="0" cellspacing="0" class="hbTable" style="width: 100%"> <thead> <tr> <th class="hbBorderBottom"> </th> <th class="hbBorderBottom"><?php __('front_adults'); ?></th> <th class="hbBorderBottom"><?php __('front_children'); ?></th> <th class="hbBorderBottom hbAlignRight"><?php __('front_price'); ?> <span class="hbRed">*</span></th> </tr> </thead> <tbody> <?php $total = 0; foreach (range(1, $_GET['cnt']) as $j) { ?> <tr> <td class="hbBorderBottom"><?php __('front_room'); ?> <?php echo $j; ?></td> <td class="hbBorderBottom"> <select name="adults[<?php echo $j; ?>]" class="hbSelect hbSelectorPeople" data-index="<?php echo $j; ?>"> <?php foreach (range(1, $tpl['room_arr']['adults']) as $i) { $selected = ( isset($STORE['all_rooms'][$_GET['room_id']][$j]) && $STORE['all_rooms'][$_GET['room_id']][$j]['adults'] == $i ); ?><option value="<?php echo $i; ?>"<?php echo !$selected ? NULL : ' selected="selected"'; ?>><?php echo $i; ?></option><?php } ?> </select> </td> <td class="hbBorderBottom"> <select name="children[<?php echo $j; ?>]" disabled class="hbSelect hbSelectorPeople" data-index="<?php echo $j; ?>"> <?php foreach (range(0, $tpl['room_arr']['children']) as $i) { $selected = ( isset($STORE['all_rooms'][$_GET['room_id']][$j]) && $STORE['all_rooms'][$_GET['room_id']][$j]['children'] == $i ); ?><option value="<?php echo $i; ?>"<?php echo !$selected ? NULL : ' selected="selected"'; ?>><?php echo $i; ?></option><?php } ?> </select> </td> <td class="hbBorderBottom hbAlignRight hbSelectorPrice"> <?php if (isset($STORE['content'][$_GET['room_id']][$j]['raw_price'])) { $price = $STORE['content'][$_GET['room_id']][$j]['raw_price']; } else { $price = $STORE['rooms'][$tpl['room_arr']['id']][$j]['price']; } echo pjUtil::formatCurrencySign(number_format($price, 2), $tpl['option_arr']['o_currency']); ?> </td> </tr> <?php $total += $price; } ?> </tbody> <?php /* <tfoot> <tr> <td></td> <td></td> <td></td> <td class="hbAlignRight hbSelectorTotal"><?php echo pjUtil::formatCurrencySign(number_format($total, 2), $tpl['option_arr']['o_currency']); ?></td> </tr> </tfoot> */ ?> </table> <p class="hbAlignRight hbBefore"> <input type="button" class="hbSelectorButton hbSelectorCancelRoom hbButton hbButtonGray" value="<?php __('front_btn_cancel'); ?>" /> <?php if ((int) $tpl['option_arr']['o_accept_bookings'] === 1) : ?> <input type="button" class="hbSelectorButton hbSelectorBook hbButton hbButtonOrange" value="<?php __('front_btn_book'); ?>" /> <?php endif; ?> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/#findComment-1516455 Share on other sites More sharing options...
Hailstone Posted July 17, 2015 Author Share Posted July 17, 2015 Anyone please? Quote Link to comment https://forums.phpfreaks.com/topic/297273-enable-2nd-dropdown-if-the-value-of-the-1st-dropdown-is-max/#findComment-1516645 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.