开发者

how to select drop down value from .cs and assign in javascript

<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>开发者_JAVA百科
            <input type="checkbox" id="activate" /> Activate
         </td>
   </tr>
</table>

I have one page called (staff-insert-update.aspx). The above code works fine for the insert mode where intially during the checkbox is selected[--select value comes] but in edit mode if the user a value checked in the checkbox and his corresponding value should be shown in the drop down instead of a default value as we do for the insert mode. Now in edit mode the user has to get his selected value when this checkbox in checked in .cs file of asp.net

looking for this solution from past 1 day. Could not find solution how to solve it any help on this would be great

thank you


I don't know if I got your question right. But I took a shot.Try this out.

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

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

function activate(e)  
{ 
    $("#theSelect").toggle((e.target.value.length>0)); 

    if (!e.target.checked)  
    { // reset selection 
        $("#theSelect option[value='--Select--']").attr('selected', 'selected'); 
    }else{
     $("#theSelect").val(($("#activate").val()));
}   
} 
</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" checked='checked' value='bar'
            /> Activate 
         </td> 
   </tr> 
</table> 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜