locked
How to make look field read only when we enter value on next field? RRS feed

  • Question

  • Hi,

    I have two look field in same list (filed A and Field B). I want when user enter data on filed A immediately field B should be readly only and vice versa. Beacuse are allow to lookup only one filed at a time. I want this function when item is adding and updating. I am new on .net coding for sharepoint. It will be great if you guys can explain me in details.

    Thanks in advanced.

    Monday, July 1, 2013 4:44 PM

Answers

  • Hi sa24,

    We could achieve this with JavaScript/JQuery. Here is an sample code for your refer.

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script><script type="text/javascript">
    $(document).ready(function(){
    $('select[title="lookupA"]').change(function(){
    if($('select[title="lookupA"] option:selected').text() != "(None)")
    {
    $('select[title="lookupB"]').attr('disabled','disabled');
    }
    else
    {
    $('select[title="lookupB"]').removeAttr('disabled');
    }
    });
    $('select[title="lookupB"]').change(function(){
    if($('select[title="lookupB"] option:selected').text() != "(None)")
    {
    $('select[title="lookupA"]').attr('disabled','disabled');
    }
    else
    {
    $('select[title="lookupA"]').removeAttr('disabled');
    }
    });
    });
    </script>

    Note:
    1. lookupA and lookupB are the name of the 2 lookup columns in my test.
    2. We can add the script to a Content Editor web part (insert the script as HTML source code) in NewForm.aspx page and EditForm.aspx page.

    Thanks & Regards,
    Emir Liu
    TechNet Subscriber Support in forum
    If you have any feedback on our support, please click here.


    Emir Liu
    TechNet Community Support

    • Marked as answer by sa24 Tuesday, July 2, 2013 8:21 PM
    Tuesday, July 2, 2013 3:22 AM

All replies

  • Open the new form.aspx / Edit form.aspx in info path form designer. Do the conditional formatting and you are good to go !.


    Thanks Santhosh V

    Monday, July 1, 2013 7:23 PM
  • i am not able to get the look up on the infopath form. Is there any way we can do through the programing.

    Monday, July 1, 2013 7:39 PM
  • Hi sa24,

    We could achieve this with JavaScript/JQuery. Here is an sample code for your refer.

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script><script type="text/javascript">
    $(document).ready(function(){
    $('select[title="lookupA"]').change(function(){
    if($('select[title="lookupA"] option:selected').text() != "(None)")
    {
    $('select[title="lookupB"]').attr('disabled','disabled');
    }
    else
    {
    $('select[title="lookupB"]').removeAttr('disabled');
    }
    });
    $('select[title="lookupB"]').change(function(){
    if($('select[title="lookupB"] option:selected').text() != "(None)")
    {
    $('select[title="lookupA"]').attr('disabled','disabled');
    }
    else
    {
    $('select[title="lookupA"]').removeAttr('disabled');
    }
    });
    });
    </script>

    Note:
    1. lookupA and lookupB are the name of the 2 lookup columns in my test.
    2. We can add the script to a Content Editor web part (insert the script as HTML source code) in NewForm.aspx page and EditForm.aspx page.

    Thanks & Regards,
    Emir Liu
    TechNet Subscriber Support in forum
    If you have any feedback on our support, please click here.


    Emir Liu
    TechNet Community Support

    • Marked as answer by sa24 Tuesday, July 2, 2013 8:21 PM
    Tuesday, July 2, 2013 3:22 AM
  • You can't get the lookup column in InfoPath, no. But you can build the form to pull from differing lists and then use conditional formatting.
    Tuesday, July 2, 2013 3:42 AM
  • how can we achieve sam functionality with object picker too. I have to use same functionality with object picker too.

    Thank you so much for help :)

    Tuesday, July 2, 2013 8:23 PM