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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Show/Hide Button based...
Power Pages
Answered

Show/Hide Button based on Dropdown selection - Portal Webforms - JavaScript

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi 

 

I am trying to disable a Submit button based on a dropdown box in a portal webform?

 

Can I do this via JavaScript?

Categories:
  • the365bit Profile Picture
    136 on at

    Hi @Anonymous ,

     

    Yes, you can do that by adding javascript in the Custom Javascript field in the "Form Options" tab of your web form step.

     

    the365bit_0-1595282976435.png

     

  • Verified answer
    H V Profile Picture
    1,510 on at

    Hi @Anonymous 

    In addition answer of @the365bit 

    If you are using Web Form:

    Go to Web Form Step -> Click on 'Form Options' tab -> Add below code in JavaScript Section:

     

    $(document).ready(function(){
    	$("#new_optionsetfieldlogicalname").change(function () {
     // Get value of your trigger field
     let currentVal = $("#new_optionsetfieldlogicalname option:selected").val();
     //do some validation
     if(currentVal == "459490001") {
     $("input[type='button'][value='Submit']").hide();
     } else {
     $("input[type='button'][value='Submit']").show();
     }
     });
     });

     

     If you are using Entity Form and Web Page, then you have to add javascript into localized content page.

    Note: You have to put your optionset field's logical name instead of "new_optionsetfieldlogicalname".

     

    If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Good Morning @hardikv , 

     

    Thank you for you help and code 🙂 

     

    i have tried this code below but doesn't seem to like the code?

    $(document).ready(function(){
    	$("#iii_submitted").change(function () {
     // Get value of your trigger field
     let currentVal = $("#iii_submitted option:selected").val();
     //do some validation
     if(currentVal == "0") {
     $("input[type='button'][value='Submit your Request']").hide();
     } else {
     $("input[type='button'][value='Submit your Request']").show();
     }
     });
     });

      

    i am sure iv changed the correct code

     

    this is the dropdown box

    MartinPAChamp_0-1595320639159.png

     

    the button

     

    MartinPAChamp_1-1595320701211.png

     

    MartinPAChamp_2-1595320729305.png

     

    Sorry still very new to JavaScript so learning

  • oliver.rodrigues Profile Picture
    9,482 Most Valuable Professional on at

    from a quick look the code looks fine

     

    can you add a few console.log("message"); in between the lines so we can see in the console where it is hitting ?

     

    also where are you placing the JS code? I would suggest the Entity Form custom JavaScript section 

  • H V Profile Picture
    1,510 on at

    Hi @Anonymous 

    Did you clear the cache?

     

    Have you checked by selecting other dropdown options? 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Sorry guys @hardikv , @OliverRodrigues  my bad, 

     

    its working now 🙂 i was sure i hit the clear cache button, i think its to early lol

     

    Thank you for your help 🙂

     

    one other quick question in webforms i have a date field that show the format as mm/dd/yyyy and would like it in dd/mm/yyyy 

     

    its it possible to change the date format via JavaScript as well? or have i missed something in the portal management?

     

    Thanks again 🙂

  • oliver.rodrigues Profile Picture
    9,482 Most Valuable Professional on at
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hey Guys @OliverRodrigues, @hardikv 

     

    Following on from the Hide/Show the button doesnt seem to default to hidden? it works fine after i have selected yes and then back to no? 

     

    On load 

     

    MartinPAChamp_0-1595333734929.png

    After selecting to yes and back to no it works

     

    MartinPAChamp_1-1595333803575.png

    is there a way to it default the button to be hidden on screen load?

     

    Many Thanks for you help 🙂

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @OliverRodrigues 

     

    Perfect worked straight away thank you 🙂

  • Verified answer
    H V Profile Picture
    1,510 on at

    HI @Anonymous 

     

    For onload, you should use below code:

    $(document).ready(function(){
    	let currentVal = $("#iii_submitted option:selected").val();
    	//do some validation
    	if(currentVal == "0") {
    		$("input[type='button'][value='Submit your Request']").hide();
    	} else {
    		$("input[type='button'][value='Submit your Request']").show();
    	}
     
    	$("#iii_submitted").change(function () {
     // Get value of your trigger field
     let currentVal = $("#iii_submitted option:selected").val();
     //do some validation
     if(currentVal == "0") {
     $("input[type='button'][value='Submit your Request']").hide();
     } else {
     $("input[type='button'][value='Submit your Request']").show();
     }
     });
     });

     

    Clear cache first and check it.

     

    If you like this post, give a Thumbs up. Where it solved your query, Mark as Solution so it can help other people. 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Pages

#1
Mohsin Ali Profile Picture

Mohsin Ali 35

#2
M Bilal Khan Profile Picture

M Bilal Khan 33

#3
11manish Profile Picture

11manish 21 Super User 2026 Season 2

Last 30 days Overall leaderboard