将值传递给默认NewForm.aspx
-
09-12-2019 - |
题
我需要将值从我的列表视图(日历)传递给默认的newform.aspx。如您所知,您可以在日历视图中的一天单击“添加”按钮。然后当天自动选择。我想要的是一个相同的东西。我想获取视图的名称(有大约20 ...),将此传递给NewForm.aspx并从ComboBox中选择一个值。任何知道如何做到这一点的人?
我不想修改每个视图以添加一些JS / jQuery代码。因此,如果可能只修改newform.aspx-page。
解决方案
I've solved it by storing values within my cookie:
General script (added on masterpage):
function GetMeetingRoomPage()
{
if (document.URL.indexOf('/sites/meetingrooms/Lists/Reservations/') >= 0)//Check if correct URL
{
var meetingRoomViewControl = "<id or class view>";
if (jQuery(meetingRoomViewControl).length)//Check if control exists
{
setCookie("meetingRoomView", jQuery(meetingRoomViewControl).html(), "1");
}
}
else
{
setCookie("meetingRoomView", "", "1");
}
}
function setCookie(c_name, value, exdays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
function getCookie(c_name)
{
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++)
{
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name)
{
return unescape(y);
}
}
}
Script within my newpage.aspx
ExecuteOrDelayUntilScriptLoaded(procAuditArgs, "sp.js");
function procAuditArgs(){
var meetingRoomView = getCookie("meetingRoomView");
if(meetingRoomView != "")
{
var meetingRoomControl = "<id or class combobox>";
jQuery(meetingRoomControl + " option").each(function()
{
if(jQuery(this).text().indexOf(meetingRoomView) >= 0)
{
jQuery(this).attr("selected","selected");
}
});
}
}