SharePoint 2007 modal dialog pop up for NewForm not working

I am trying to get a modal dialog to pop up that displays the NewForm for a SharePoint 2007 List.

I am using the following code:

$( document ).ready(function() {
function openInModalDialog()
{
  var url = "http://itsusmpw00799:56789/prd/hcctesting/Lists/PharmSLT_Meetings/NewForm.aspx";
  commonShowModalDialog(url,"resizable: no; status:no; scroll: no; help: no; center: yes; dialogwidth:800px; dialogHeight:500px;",RetrieveItemValue);
}
});

$(document).ready(function(){
   $("#add_meeting").click(function(event){
     openInModalDialog();
   });
 });

Open in new window


in addtion, the aspx page with the link has the following code:

<div class="container">
<table cellpadding="10">
<tr height="50"><td></td></tr>
<tr><td>
<b>Select Meeting:</b><br>
<select></select>
</td>
<td valign="middle">
<a id="add_meeting">Add Meeting</a>
</td
</tr>
</table>
</div>

Open in new window


I am getting an Object expected error. Any suggestions to get this to load properly? I think I have all the correct script references.
Adam EhrenworthLead Technology AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
two comments on this:
1. Remove the function outside of the document.ready event
I would move the function outside and therefore remove the complete first document.ready handler. Second I would add the preventDefault on the a click:
function openInModalDialog()
{
	var url = "http://itsusmpw00799:56789/prd/hcctesting/Lists/PharmSLT_Meetings/NewForm.aspx";
	commonShowModalDialog(url,"resizable: no; status:no; scroll: no; help: no; center: yes; dialogwidth:800px; dialogHeight:500px;",RetrieveItemValue);
}

$(document).ready(function(){
	$("#add_meeting").click(function(event){
		event.preventDefault();
		openInModalDialog();
	});
});

Open in new window


2. Question on the internal function
How does the function commonShowModalDialog look alike and what is the third parameter RetrieveItemValue?

HTH
Rainer
Adam EhrenworthLead Technology AnalystAuthor Commented:
Thank you for providing those changes... I am not sure I am clear on what you mean by "look alike" and the ReturnItemValue was in other code I found online.. it may not be necessary.

I am basically trying to get the New Form for a list and for a Document Library to appear in the dialog window.

Appreciate the assistance.

The current code you provided is getting the following error

openInModalDialog is not defined
Rainer JeschorCommented:
Hi,
the following works on my SharePoint 2007 dev environment:
<script type="text/javascript" src="_layouts/scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
	var RetrieveItemValue = null;
	jQuery(document).ready(function(){
		jQuery("#add_meeting").click(function(event){
			openInModalDialog();
		});
	});
	function openInModalDialog()
	{
		var url = "https://dev.rainerj.de/Lists/DummyList/NewForm.aspx";
		commonShowModalDialog(url,"resizable: no; status:no; scroll: no; help: no; center: yes; dialogwidth:800px; dialogHeight:500px;",RetrieveItemValue);
	}
</script>
<div class="container">
	<table cellpadding="10">
		<tr height="50">
			<td colspan="2"></td>
		</tr>
		<tr>
			<td>
				<b>Select Meeting:</b><br>
				<select></select>
			</td>
			<td valign="middle">
				<a id="add_meeting">Add Meeting</a>
			</td>
		</tr>
	</table>
</div>

Open in new window


Important is just that the jQuery library is loaded.

I used Chrome and the built-in dev tools (press F12 to start them) and have no errors in the console.

HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Rainer JeschorCommented:
Additional note:
I stored the above code in one text file, named this "ContentDemo.html" and uploaded the file to a document library in SharePoint. Then I added a content editor web part to another page and instead of pasting the code directly I just set the link to the previous uploaded HTML file.
Adam EhrenworthLead Technology AnalystAuthor Commented:
Thank you! I figured out my error almost right after and your code is definitely cleaner.

One important follow up that I have not been able to successfully search for..

Where and what code on the custom aspx page do I need to include to have the modal dialog box close if the use either enters enters info and selects OK or if they hit Cancel?

Adam
Rainer JeschorCommented:
Hi Adam,
could you please do me a favour? If the provided code did solve your issue, please mark the answer as solution and close this question. For your follow up question please create a new question and reference this one - and I will in the meantime work on a solution.
Thanks and KR
Rainer
Rainer JeschorCommented:
Hi Adam,
thank you very much. I am working on the dialog close question - but thats a tricky one :-(
Adam EhrenworthLead Technology AnalystAuthor Commented:
I understand. Any help you can provide is great.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.