
Hailstone
New Members-
Posts
6 -
Joined
-
Last visited
Everything posted by Hailstone
-
Hi, Having problem with onchange.. the price doesn't change if I select more than 1 in adult dropdown and also on the child dropdown.. please help.. here's my code on javascript and php $(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); } }); }); PHP <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>
-
Enable 2nd Dropdown if the Value of the 1st dropdown is max
Hailstone replied to Hailstone's topic in Javascript Help
Anyone please? -
Enable 2nd Dropdown if the Value of the 1st dropdown is max
Hailstone replied to Hailstone's topic in Javascript Help
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> -
Enable 2nd Dropdown if the Value of the 1st dropdown is max
Hailstone replied to Hailstone's topic in Javascript Help
Got a problem.. if only 1 selection the Book/Go button doesn't work.. -
Enable 2nd Dropdown if the Value of the 1st dropdown is max
Hailstone replied to Hailstone's topic in Javascript Help
I LOVE YOU!.. thanks for the help! -
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.