开发者

javascript how to make the dropdown value to reset to intiall value(checking the check box)

"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 开发者_Go百科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-"


This should do it:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜