2

I have problem with getting values from select option when use JQuery UI $('#id').combobox(). When i use simple JQuery without Ui it work but when i use Ui it can't get Value. Here some of my HTML code:

<table>
    <tr>
        <td>Reset by: </td>
        <td>
            <select name="resetType" id="resetType">
                <option value="email" selected>Email</option>
                <option value="phone">Phone's Number</option>
                <option value="username">Username</option>
            </select>
        </td>
    </tr>
    <tr>
        <td id="type"></td>
        <td><input type="text" name="type"/></td>
    </tr>
</table>

Here my JQuery Code:

$(function(){
    $('#resetType').combobox(); // Code have Problem
    switch($('#resetType').val()){
    case 'email':
        $('#type').html('Email: ');
    break;
    case 'phone':
        $('#type').html('Phone: ');
    break;
    case 'username':
        $('#type').html('Username: ');
    break;
    }
})

1 Answer 1

1

I did [name*="type"] here because you didn't give that textbox an ID or anything, so i'm simply searching for it by name attribute.

$('#resetType').on('change', function () {
    $('[name*="type"]').val($(this).find('option:selected').val());       
});​

Here's a working demo: http://jsfiddle.net/JwB6z/2/

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

1 Comment

But when i use $('#resetType').combobox() to display JQuery UI my code will error can't get values. $('#resetType').combobox(); $('#resetType').on('change', function () { $('[name*="type"]').val($(this).find('option:selected').val()); });​

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.