views:

275

answers:

1

hi, "INSERT MODE"

i have check box in one "tr". and another dropdown control in another "tr" intially dropdown control will be invisiable intially .

but once the user checks the check box. the dropdown control should be visiable and he can select the value. but again the user unchecks the check box the dropdown should be set to default value that is "--selec--"

"UPDATE MODE" intailly checkbox.Test = dt.cloumn["state"].tostring();

if(checkbox.Test!= "")
{
checkbox.checked=true;
//then  value  dropdown  value  should  be  shown like"india"
}
else
{
checkbox.checked="false"
//then  value  dropdown  value  should   be  default "--select"
}

in insert mode checkbox willbe unchecked in update mode if checkbox in checked then the value of dropdown should be shown"india" in update mode if checkbox in unchecked then the value of dropdown should be shown default"-select-"

+1  A: 

This should do it:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"&gt;&lt;/script&gt;

<script type="text/javascript">
    $(document).ready(function(){
        $("#theSelect").toggle(0);
        $("#activate").click(activate)
    })

    function activate(e) {
        $("#theSelect").toggle((e.target.checked));

        if (!e.target.checked) {  // reset selection
            $("#theSelect option[value='--Select--']").attr('selected', 'selected');
        }
    }
</script>
<table>
    <tr>
        <td>
            <select id="theSelect">
                <option value="--Select--">--Select--</option>
                <option value="foo">foo</option>
                <option value="bar">bar</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="activate" /> Activate
        </td>
    </tr>
</table>
Lance Rushing
thanks for the replay as here you know that "-Select-" will come at "0" postion but in my case select will be the last postion in dropdown <td> <select id="theSelect"> <option value="foo">foo</option> <option value="bar">bar</option> <option value="--Select--">--Select--</option> </select> </td> because today my dropdown values may contain 5 items . in future it may contain 10 items under it. so how will i place my select value firist in bropdown on clicking checking box
prince23
made few changes worked fine to suit my needs. thanks Lance Rushing
prince23