1

I've searched quit a while on the internet but couldn't found what i wanted.

How to disable a text field when there is a select drop down selected with value (not emtpy)?

Also it would be nice to toggle it. When there is no option selected in the select drop down (no value) the user can type in the text field

I found something similar code but here it checks if the value is equal to "/\Custom\b/gi" I want that it checks on if something is selected or not?

$('#Select_Font, #Enter_Text').attr('disabled', 'disabled');
$('.dropdownstyle').change(function () {

    var present = $(this).val().match(/\Custom\b/gi) == null ? true : false;
        if(present){
            $('#Select_Font, #Enter_Text').attr('disabled', 'disabled');
        }
        else{
            $('#Select_Font, #Enter_Text').removeAttr('disabled');
        }
});

Source: How to enable or disable drop-down or text-box on selection other drop-down?

Is that possible? Thanks in advanced.

edit:

html

<div class='row'>
    <div class="large-6 columns">
        <label for="group">Group

            <select name="selectGroup" id="selectGroup">
                <option value="">Choose a group</option>

                <?php
                while ($row = $result->fetch_assoc()) {
                    echo '<option value="' . $row['group'] . '">' . $row['group'] . '</option>';
                }
                ?>

            </select>
        </label>
    </div>

    <div class="large-6 columns">
        <label for="group">Or make a new group
            <input type="text" name="makeGroup" id="makeGroup"/>
        </label>
    </div>
</div>
Community
  • 1
  • 1
Proliner
  • 41
  • 1
  • 6

1 Answers1

1
$('#selectGroup').change(function () {
    $('#Select_Font, #Enter_Text').prop('disabled', this.value.length);
});

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388
  • When you have typed some value in the textfield and selected a group (option) the value is still in the textfield, i have used $('#textCategorie').removeAttr('value'); but that didn't worked – Proliner Mar 29 '14 at 20:53
  • That's an unrelated question that you didn't really ask, but you'd do that like so -> **http://jsfiddle.net/adeneo/9reSb/5/** – adeneo Mar 29 '14 at 20:58