Using below code I am loading share point new list item form in the SP Modal Dialog. Now I want to hide Cancel button of that form.

How can I do that ?

<script type="text/javascript">

var context;
var web;
var user;
var siteUrl = _spPageContextInfo.siteServerRelativeUrl ;
//var loginName = _spPageContextInfo.userLoginName;
var currentLoggedinUser = _spPageContextInfo.userLoginName;
var userTitle;
var flag=true;
var options = { title: "Announcements - New Item",url:"http://sp-qc-01:2525/Lists/testSurvey/NewForm.aspx"};
function init() {
context = SP.ClientContext.get_current();
web = context.get_web();


function getCurrentUser() {
user = web.get_currentUser();

context.executeQueryAsync(onGetUserNameSucces, onGetUserNameFail);
function onGetUserNameSucces() {
// TODO: implement your own succes handler

function onGetUserNameFail(sender, args) {
// TODO: implement your own fail handler and do some logging

function retrieveListItems() {
      var oList = context.get_web().get_lists().getByTitle('testSurvey');
     var camlQuery = new SP.CamlQuery();

  camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Author\' /><Value Type=\'User\'>'+ user.get_title()+'</Value></Eq></Where></Query></View>');
     this.collListItem = oList.getItems(camlQuery); 
    context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));


function onQuerySucceeded(sender, args) {       

    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();



function onQueryFailed(sender, args) {
    alert('Error: ' + args.get_message() + '\n' + args.get_stackTrace());


2 Answers 2


Use the below Script to hide the Cancel button.


You can find all the settings you can pass to SP.UI.ModalDialog here

Unfortunately, you can't open the dialog without "cancel" button in it.

What you can do is to edit NewForm.aspx page.

  1. Go to your list/library
  2. Click "new", this will redirect you to NewForm.aspx
  3. Edit Page
  4. Add Content Editor Web Part somewhere above your form
  5. Add the following css to your CEWP:

    input.ms-ButtonHeightWidth[value="Cancel"] { display: none; }

  6. Save the page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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