tags:

views:

52

answers:

1

hi,

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

i have one page called (staff-insert-update.aspx) the above code works fine for the insert mode where intially during the check box is selected[--select value comes] but in edit mode if the user a value checked in the check box 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 check boc 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

+1  A: 

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"&gt;&lt;/script&gt; 

<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>
krishna
hey thanks for the replay but even in upadate mode if my dropddown had a value selected it is not showing that value instead of that it is showing the default select value which should not happen
prince23
Edited.Check this version.
krishna
ur code worked fined thanks a lot
prince23