Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to show/hide a Field according to the selected value of a Choice field. How can i achieve this with javascript or AJAX?

Edit:

I tried this but, i cant even get the value of the selected value for the lookup dropdown:

$(document).ready(function() {

       $('select[id$="ctl00_m_g_4baff930_989d_4f64_8728_9fb22af0d590_ctl00_ctl05_ctl09_ctl00_ctl00_ctl04_ctl00_Lookup"]').live("change", function()
        {
            alert($(this).val());
       });
   });
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
<script type="text/javascript">
 $(document).ready(function() {

           $('select[id$="dd1"]').live("change", function()
            {

                if($(this).val()=='Completed')
                    {   
                            var title=$("[id$='textbox1']");    
                            title.show();
                    }
                    else
                    {
                       var title=$("[id$='textbox1']");
                       title.hide();
                    }

           });
       });

new answer

$('#selectField').change(function(){
if($('#selectField').val() == 'N'){
    $('#secondaryInput').hide();
} else {
    $('#secondaryInput').show();

} });

I assume choice field is ur dropdonw. dd1 will be ur choice field id and textbox1 will be ur another filed id. This is just a sample but u can accomplish ur requirement like this. Dont forget to include jquery before this. I suggest u to use infopath form instead of sharepoint list forms.

Regards,

Dhaval

share|improve this answer
    
And how to find the ID s of the fields? From browser's View Source? –  ozdogan Jan 30 '13 at 9:29
    
BTW,additionally i must check the selected value of the dropdown. Then show or hide the Text Field according to the selected value. –  ozdogan Jan 30 '13 at 9:32
1  
yes..only the way u can find..Sharepoint automatically generate control id like 'ctl00_m_g_49979d6a_ba67_4c70_82b0_59e0fa0787d1_ctl00_ctl05_ctl00_ctl00_ctl00_ct‌​l04_ctl00_ctl00_TextField' thats why i have used $("[id$='textbox1']"). For this id u can use like $("[id$='TextField']"). And if there are multiple textbox in a form then you have to match title attribute of control too. –  Dhaval Kariya Jan 30 '13 at 9:34
    
can you show me an example of: "And if there are multiple textbox in a form then you have to match title attribute of control too." –  ozdogan Jan 30 '13 at 9:37
1  
for that u have check for all controls inside the form with 'TextField' and then get title attribute like $("[id$='TextField']").val( $(this).attr('title') );. And for checking selected value of dropdown pls see into my updated anwser. –  Dhaval Kariya Jan 30 '13 at 9:43
show 5 more comments

First Provide the ID for the Row contains your Field.

Add the Following Script:

function hidefield()
{
   if (document.getElementById("checkboxid").checked)
   {
      document.getElementById("rowid").style.visibility = "collapse";
   }
}

Call this function in onclick event of the Checkbox.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.