Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to pass values from my list-view (calendar) to the default newform.aspx. As you propably know, you can click the "add" button on a day within the calendar view. Then the day get's automaticly selected. What I want is a bit the same. I want to get the name of the view (there are about 20...), pass this to the newform.aspx and select a value from a combobox. Anyone who knows how to do this?

I don't want to modify each view to add some js/jquery code. So if possible only modify the newform.aspx-page.

share|improve this question
1  
You could add JS globally (AdditionalPageHEad, ScriptLink, edit MasterPage etc) though, and make a conditional for URL or some information from DOM. Would this suffice? –  eirikb Oct 22 '12 at 11:31
add comment

1 Answer 1

up vote 0 down vote accepted

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");
            }
        });
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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