Jump to content

Recommended Posts

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.post-179271-0-06240700-1436775326_thumb.png

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. 

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>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.