2

i am a beginner in coding. i have this kind of code.

<div class="row_add_house">
    <span><?php echo _REALESTATE_MANAGER_LABEL_LISTING_TYPE; ?>:</span>
    <span><?php echo $listing_type_list; ?></span>
</div>

At front end, this will appear as a drop down selection, and the $listing_type_list appear with three selection:

  1. select
  2. house for rent
  3. house for sale

and the 'select' is set by default. how can i set 'house for rent' as a default selection? anyone please help me.

        if ($house->listing_type != 1) {
        ?>
            <tr>
                <td class="first_td" align="right">
                    <strong><?php echo _REALESTATE_MANAGER_LABEL_LISTING_TYPE; ?>:</strong>
                </td>
                <td width="270px" align="left">
                    <?php
                    $listing_type[0] = _REALESTATE_MANAGER_OPTION_SELECT;
                    $listing_type[1] = _REALESTATE_MANAGER_OPTION_FOR_RENT;
                    $listing_type[2] = _REALESTATE_MANAGER_OPTION_FOR_SALE;
                    echo $listing_type[$house->listing_type];
                    ?>
                </td>
            </tr>
        <?php

this is another part of the coding. this seems to be the 'if' statement of the dropdown menu, if the option is selected to 'for rent'of the dropdown menu. there are the option for $listing_type_list. how can i set the option automatically to select the $listing_type[1]?

3
  • add selected to the <option> attributes ie <option value='house for rent' selected> Commented Aug 17, 2017 at 18:18
  • Share html of $listing_type_list ? Commented Aug 17, 2017 at 18:18
  • How does this get converted to a drop down list? It doesn't look like that's how this HTML would show up by default. Commented Aug 17, 2017 at 18:42

1 Answer 1

1

It would be more clear if you can provide value of $listing_type_list.

Anyway, to make any option of drop down as default selected, you have to write 'selected' property as below:

<option selected="selected">

Hope it will resolve your query.

Sign up to request clarification or add additional context in comments.

3 Comments

This will work if the list is not dynamic. if it is as in an array, you may have to look at working with array keys.
True! It depends on the value of variable. In dynamic scenario it should check for 'house for rent' then apply 'selected' property.
Mr. rohit, i have provided the value for $listing_type_list. in my question. hope u can help me to solve this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.