web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / JavaScript to clear lo...
Power Pages
Answered

JavaScript to clear lookup value in portal form

(0) ShareShare
ReportReport
Posted on by 132

Hi everyone,

I'm quite new to working with power portals and can not find a solution. I believe there exists very simple code which would help me out.

I need to reset the lookup value (city) of the field when another one is changed (province) when editing or creating a new record. So far I have the below code but it just resets the lookup value, but doesn't  clear it from the form and doesn't let me save the form (city is a required field), so it's a bit confusing, maybe I just left a mistake in code:

$(document).ready(function () {
$("#cr52c_province").change(resetfield);
resetfield();
});

function resetfield() {
$("#cr52c_city").attr("value",null);
$("#cr52c_cityId").attr("value",null);
$("#cr52c_city").attr("value",null);
}

 

Moreover, the form cannot be saved even if the province field is not modified, so every time when the form is opened in edit mode, the city needs to be selected once again in order to save the edited form.

Categories:
I have the same question (0)
  • Verified answer
    Fubar Profile Picture
    8,346 Super User 2025 Season 2 on at
    // where "primarycontactid" is the field anme
    
    $("#primarycontactid").val('');
    $("#primarycontactid_name").val('');
    
    // if it is a Customer lookup could optioanly also
    
    $("#primarycontactid_entityname").val('');

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 70 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard