Add new lookup item on the fly

Feb 23, 2012 at 6:39 PM

If I understand correctly, the $().SPServices.SPLookupAddNew function adds a link to the lookup source list (newform).

I am interested in taking this one step further, and have the new item inserted in the drop-down, without leaving the form. Has this been done before?

My initial thought was to trigger a page refresh, but there's one issue: if the user has already started filling out the form, the information he/she entered is lost.

Thanks!

Coordinator
Feb 23, 2012 at 10:23 PM

There's been a lot of back and forth on this over the years, and I don't have a good solution.

Originally, I built this function just because I found it helpful in building up my test lists. It's taken on a life of its own.

M.

Feb 24, 2012 at 1:44 AM

Thanks for the reply Marc.

I am working on SP 2010, and I was able to implement the "add new" button (I didn't use SPLookupAddNew), have the new form open in a modal dialog, and trigger a page refresh that updates the lookup. I asked on Stackoverflow about avoiding to lose data, and it seems that the only way would be to use cookies or local storage.

For the record, I also have a usability concern about this design. The field with the add new button is actually the child of a cascading lookup. I am concerned that the users will be prompt to click on "add new" if they don't see any entry, without realizing that they need to select the parent first.

Feb 24, 2012 at 10:42 AM

I have built something for this that seems to work fine without losing data and you do not need to leave the form. I know that Marc is super busy but I can send you all the stuff again to do this. I have done it many times and it has not failed yet. (Knock on the proverbial piece of wood!)

Feb 24, 2012 at 4:21 PM

Very interesting, thanks for the offer! Just let me know how I can get more information.

Are you saying that your technique doesn't even need a page refresh, and will just update the lookup on the current form with the new item?

Feb 24, 2012 at 8:46 PM

To add items to the lookup field, you can use whatever method you prefer. A modal popup box or whatever as long as the result adds the new item to the lookup of choice. Also remember that the result should pass the id as well. The following code is the approach that I took to get this done.

function PreSaveAction() { 
    var qv = $().SPServices.SPGetQueryString(); 
    if (qv["PreSave"] == "skip") { 
        return true; 
    } 
    else { 
        var loc = new String(window.location); 
        loc = loc.split("?"); 
        var formpage = loc[0]; 
        formpage += "?PreSave=skip"; 
        $("#aspnetForm").append(""); 
        $("#iframea").attr("src", formpage); 
        setTimeout("copyfields()", 4000); 
    } 
} 
 
function copyfields() { 
    try 
    { 
        var i = 1; 
        $("td.ms-formbody").each(function() { 
            $(this).attr("id", "tdelement_" + i); 
            i += 1; 
        });  
        i = 1; 
        $("#iframea").contents().find("td.ms-formbody").each(function() { 
            $(this).attr("id", "tdelement_" + i); 
            i += 1; 
        }); 
        for (var z = 1; z < i; z++) { 
            var tid = "tdelement_" + z; 
            $("#iframea").contents().find("td[id='" + tid + "']").html($("td[id='" + tid + "']").html()); 
        }  
    } 
    catch(e) {alert("Error " + e);} 
    // Once copied submit the form and then redirect to the original source page. 
    $("#iframea").contents().find("input[name*='SaveItem']").trigger('click'); 
    setTimeout("refreshpage()", 3000); 
} 
 
function refreshpage() { 
    var qv = $().SPServices.SPGetQueryString(); 
    var source = new String(qv["Source"]);   
    window.location = source; 
} 

The purpose of this code which would be placed on the form page is basically that when you save the form, it creates a hidden iframe with an empty copy of the same form and this form will accept the new field! It copies the form data using jQuery and then triggers the save button for the hidden form and voila! It refreshes the page back to the original source. The code may need to be tweaked if your pages are differen, but for the most part this has always worked. I give it a 98 on a 100 point scale just due to the setTimeout functions. These could also be tweaked depending on the reliability of your web server. Also, I am not sure that the .find() function is correct for the newest version of jQuery.

Hope this makes sense!

Feb 24, 2012 at 9:41 PM

mmm... this looks like an SP-evil trick!

I think I get the idea of the hidden iframe, but I am not sure to understand the code. For example, what is this line: $("#aspnetForm").append("") ?

Would you mind adding some details? For example when you say "form", are you referring to the form that has the lookup field, or the form that adds an item to the source list? Maybe we could take an example, like a list of cars that have a "make" lookup?

Feb 24, 2012 at 10:26 PM
Edited Feb 24, 2012 at 10:34 PM

Yes, this is one of my more evil ones, but it does work! First, I need to correct an omission in the copy that you discovered right away! The proper code is:

$("#aspnetForm").append("<iframe id='iframea' style='display:none;'/>"); 

No idea why that got dropped! So first the code will check to see if it is supposed to skip the Presave action so it does not end up in a never ending loop.

function PreSaveAction() { 
    var qv = $().SPServices.SPGetQueryString(); 
    if (qv["PreSave"] == "skip") { 
        return true; 
    } 

This returns true to skip my test of creating and submitting a frame. If you have other PreSaveAction code to run it should go here before the return true statement. If it fails this test it means that it should create the hidden iframe and redraw the form.

else { 
        var loc = new String(window.location); 
        loc = loc.split("?"); 
        var formpage = loc[0]; 
        formpage += "?PreSave=skip"; 
        $("#aspnetForm").append("<iframe id='iframea' style='display:none;'/>");
        $("#iframea").attr("src", formpage); 
        setTimeout("copyfields()", 4000); 
    } 
} 

Notice that here I add the PreSave=skip to the url so that it will skip creating another iframe! I set the iframe's source and then run the copyfields function after 4 seconds. This gives the system time to draw the form and so far seems to be a good time to use. The copy fields function does a few things which is wrapped in a try/catch:

function copyfields() { 
    try 
    { 
        var i = 1; 
        $("td.ms-formbody").each(function() { 
            $(this).attr("id", "tdelement_" + i); 
            i += 1; 
        });  
        i = 1; 
        $("#iframea").contents().find("td.ms-formbody").each(function() { 
            $(this).attr("id", "tdelement_" + i); 
            i += 1; 
        }); 
        for (var z = 1; z < i; z++) { 
            var tid = "tdelement_" + z; 
            $("#iframea").contents().find("td[id='" + tid + "']").html($("td[id='" + tid + "']").html()); 
        }  
    } 
    catch(e) {alert("Error " + e);} 
    // Once copied submit the form and then redirect to the original source page. 
    $("#iframea").contents().find("input[name*='SaveItem']").trigger('click'); 
    setTimeout("refreshpage()", 3000); 
}
The assumption here is that you have not changed the class names in the default forms. 
I realized that these are different in 2010 on some forms but they can be changed. 
Basically the idea is to loop through each of the iframes form controls and 
replace the html of them with the html of the form you have already filled out. 
I may need to write a 2010 version as this was from my 2007 forms!  
Once all of the controls on the iframe have been replaced, it will then trigger the click 
of the form and save the item. Then it just calls that refreshpage script to go back to 
the original source page. As I said earlier, you can use whatever method you want to 
add the new item to the lookuplist and field. This code just ensures that you can save 
the form with the new values. I might need to make a blog post on this 
with some examples from a 2010 site that I think I have somewhere!
Mar 26, 2012 at 6:44 PM

Christophe, did you make any headway with this at all?

Mar 26, 2012 at 6:54 PM

No, this is still in my to-do list and I haven't even tested it yet. I am still hesitant which route to take, and I am also considering cookies.

Jul 10, 2012 at 4:06 PM

Hello,

I am attempting to implement the code written by spevilgenius in order to "save" the form and have the prior fields filled out when a user adds in a new value via the $().SPServices.SPLookupAddNew function.  In the NewForm page, I added in the provided functions in  CEWP and inside their own <script language="javascript" type="text/javascript"></script> tags.

However, whenever I click on the prompt to add in the new functions and either add or cancel the new item, the form is still cleared out. I haven't changed any of the class names and am using jquery-1.7.2 & spServices 0.7.1a

Is there something I'm missing or need to customize specifically for my form (changes to your provided code other than the .append(...)?  Do I need to add the functions to the form on the other "Add New [Lookup Value]" form?

I see that there is a "Save" form, I'm assuming this is an action that is done via the provided methods? (I don't have a save button on my form). Also I wasn't sure if the .find() is used the same way in these new versions.

I appreciate the help.

 

Jul 10, 2012 at 4:27 PM

Are you doing this on 2010 or 2007? How are you using the SPLookupAddNew function? If I understand this, it should allow you to add the item and return the items id and value in some form. This is what you would add the the lookup field via code. This code goes on the form that has the lookup on it. Whatever "button" or "link" you have on the form that saves it is what is actually "clicked" by jQuery.  This line is what does this and I just used the "View Source" option in IE to see what the button was called:

 $("#iframea").contents().find("input[name*='SaveItem']").trigger('click'); 

Hopefully this will help you out!

Jul 10, 2012 at 5:47 PM
Edited Jul 10, 2012 at 5:49 PM

Hello, I am using 2007.  For the SPLookupAddNew function, I am simply using it as a feature to add new items to the current list/lookup that is utilized in the custom list form. I implemented it using the traditional way shown in the documentation.

$().SPServices.SPLookupAddNew({ lookupColumn: "Region Name", promptText: "Add new {0} " });

On the form, I used the functions you created above, A user opens a custom list form comprised of text boxes and lookups (that are using the $().SPServices.SPCascadeDropdowns as well)

When the user gets to the lookup fields &  doesn't see the value they'd like to input:

  1. He/She clicks the text  "Add new [lookup item]"
  2. Brought to another form to add in the value of the item (Title and other info)
  3. Clicks OK
  4. Is brought back to the original form

As you stated, the returned fields should come back, but I really think it's not "saving" once I go to the other form (after clicking the "Add new [lookup item]" or it is not reloading what it did save, since the form is blank again after the "Add new [looup item]" process is complete. Is there anyway to confirm this is going through correctly? Before and after I use the addNewLookup?

Thanks again!

 

Jul 10, 2012 at 6:34 PM

Ok, I see what you are saying now. I had never used that feature and there are a few things that you can do. If you make the SPLookupAddNew open the page in a popup window, this might help. I had just been using a popup to a custom form to add the new item into the lookup and letting this return the information back to the page. I am sure that there are ways to make that function work as a popup.

Jul 19, 2012 at 9:01 PM
spevilgenius wrote:

If you make the SPLookupAddNew open the page in a popup window, this might help.

Ah great, I'm not partial to using the function to create the new lookup fields, I was just hoping it wouldn't wipe the page (which it unfortunately does). I can definitely like to the "new item" of the lookup list and put that in there.  You mentioned this link should go to a popup, can you please elaborate more on how you created that or reference an example of doing so.
Thanks!

Sep 5, 2012 at 4:34 PM
Edited Sep 5, 2012 at 4:36 PM

Quick update: I've done some research on this in the past few months. Persistence on form reload is actually a common issue, and the way to address it these days is to use local storage (works on IE8+). For example this recent tutorial explains the steps:

http://www.netmagazine.com/tutorials/make-disaster-proof-html5-forms

Sep 13, 2012 at 8:09 PM

Christophe and Lets...

Here is a rather easy solution to this using SP2010 modal dialog so you don't loose info on the main form:

http://spservices.codeplex.com/discussions/228927

Since it uses modals it will not work on 2007. it's not evil enough :-)

HTH,

Josh

Sep 13, 2012 at 9:57 PM
Edited Sep 13, 2012 at 10:08 PM

Thanks Josh, this is an elegant solution. And adding a modal interface to make it work in SP 2007 should not be very difficult. I'll still stick to my approach because it's more generic (for example in the case of lookups with multiple selects).

[Edit] I just read your reply from today, and it's true that reloading the page also addresses the case of multiple users pushing simultaneous updates (although it shouldn't be a major issue in lookup lists).

Oct 24, 2012 at 2:45 PM
ChristopheHumbert wrote:

Quick update: I've done some research on this in the past few months. Persistence on form reload is actually a common issue, and the way to address it these days is to use local storage (works on IE8+). For example this recent tutorial explains the steps:

http://www.netmagazine.com/tutorials/make-disaster-proof-html5-forms


Has anyone tried this method???? My code worked inconsistently.

Oct 24, 2012 at 3:08 PM

bcobra,

Christophes post inspred me to try Web Storage and I've used it many times since.  Not with spservices per-se, but I've used it to store a list of items after looking them up from an SP list using web services.  Web storage has two types, localStorage & sessionStorage.  I think in most cases sessionStorage is what you'll use since localStorage persists beyond the life of the current browser session.  In other words, if you save & retrive the contents of your form in localStorage, the form will fill in with those values every time which is not desirable.  sessionStorage works great in modern browsers!  Saves a lot of round trips to the web services.

Often when dealing with list items we have an array of items returned and the handy JSON.stringify and JSON.parse methods convert the array to and from a string respectively for sessionStorage.  Here is a snip of code I use for populating autocomplete boxes in sharepoint.  It's specific to my requirements, but basically it trys to set the listItems array from sessionStorage then if the array is still empty (cuz sessionStorage doesn't caontain the items yet) it queryies the list and then saves the results in sessionStorage.  This prevents the list from being queried every refreshh for the same browser session which was required in this case since I was filtering a list view and every filter-apply is a page refresh.

var listItems = [];
var ctl =  $("#" + targetWPID).find('input[readOnly]');//
if((ctl!=null)&&(ctl.attr('aria-haspopup')!=true)){
    try { listItems = JSON.parse(sessionStorage.getItem(storageName));}
    catch(e) {listItems =[]; alert("Error " + e);}

if(listItems!=null){
//alert('localStorage: ' + listItems.length);   
}
else{
listItems =[];

wsBaseUrl = listBaseUrl + '/_vti_bin/';
listName = config[0].split('/');
listName = listName[2];
sourceFIN = config[2]
var query = "<Where><IsNotNull><FieldRef ID='"+sourceFIN+"' /></IsNotNull></Where>";
var res = queryItems(listName,query,[sourceFIN]);
    // Build array of unique values - might be slow if list contains large amounts of data
    $.each(res.items,function(i,item){
        var currVal = item[sourceFIN];
        if($.inArray(currVal,listItems)==-1){
            listItems.push(currVal);
            try { sessionStorage.setItem(storageName,JSON.stringify(listItems));}
    catch(e) {alert("Error " + e);}
        }
    });

HTH,

Josh

Oct 24, 2012 at 4:59 PM
Edited Oct 24, 2012 at 5:11 PM

Sorry to anyone that tried to contact me! My email has changed and I was not able to reply directly!

I have never been able to get localstorage or sessionstorage to work in IE 8 or 9, or any browser for that matter! What am I doing wrong!! I think it requires HTML 5 which is not feasible yet.

 I think this could be useful.

However, so far for me, my "EVIL" solution seems to work for me cross browser and in 2007 and 2010. Unfortunately it appears too complex or my explanation skills are just too poor to make it work for others which I do apologize!

Oct 24, 2012 at 5:29 PM

genius,  I like your solution of saving the form in a hidden iframe.  For sessionStorage, I prefer to save the fields in a jQuery object array like so:

http://sharepointjavascript.wordpress.com/2010/04/07/revised-function-init_fields/

That way you can refer to the fields like this:  var titleFieldTR = $(fields['Title']);

Web storage is supported in Internet Explorer 8+, Firefox, Opera, Chrome, and Safari.

Can't say what's wrong, but you can Try it out here:

http://www.w3schools.com/html/html5_webstorage.asp

MS documentation:

http://msdn.microsoft.com/en-us/library/cc197062(v=VS.85).aspx

HTH,

Josh

Oct 25, 2012 at 6:55 AM

I have tried the local storage route but the refresh back to the parent page in $().SPServices.SPLookupAddNew  is not the exact link the parent page started on so the web storage values dont appear. If i hit back on the browser and browse back to the parent page and then hit reload the values appear. Is there a way to commit the parent page values to the list before opening the lookup list for the new entry?

Oct 25, 2012 at 1:39 PM

@bcobra

Yes there is... I tweeted about this a few days ago:

https://twitter.com/iOnline247/status/259310581008457728

I was actually working on a very similar problem when using the code above.  What you can do is use a modal within a modal ( I know, wonky but it works ).  Prior to the *lookup* modal being opened, .serialize() the form and store it in the parent page using the selector above and $.data(). When the modal is closed, you can fire a callback that will deserialize the data stored in the parent page and repopulate the form with what was already filled in (People pickers may be a pain using serialize!).

I don't have any code to back this up, but I'm sure it can be done based on my experience with modals in SharePoint. I actually tried to rewrite this function a few months back and didn't think about this approach.


Cheers,
Matthew 

Oct 25, 2012 at 2:45 PM

bcobra,

$().SPServices.SPLookupAddNew doesn't use SP2010 modal dialogs.  Perhaps Matthew is refering to this post where russgrove acheived similar using modals:

http://spservices.codeplex.com/discussions/228927

Sounds like your sessionStorage is working, but the newform is redirecting to a different URL as you said.  What specifically is different in the URL when you compare the before addnew and after addnew?  The function appends the current url to the 'source' querystring when you click addnew link.  This is meant to redirect you back to the same page.  This could be problematic if you're initial form (the one with the lookup column) is opening in a modal dialog.  What happens if you disable dialogs on that list? Have you tried setting option newWindow: true ? 

The prob with committing the item to the list before addnew is if you're part way through the form and have required fields not yet filled.  That idea is also discussed in the post above.  If required fields are not an issue, then you could try to commit and then redirect with ID, but I think it would be more difficult than going with the modal approach by russgrove.

HTH,

Josh

Oct 25, 2012 at 4:47 PM

modal is turned off. the only differnce is the source, which in theory shouldn't be different:
page before:
&Source=http%3A%2F%2F---%2E---%2E---%2Fsites%2Fcgh%2FSteering%2Fwgleads%2FADS%2FLists%2FReports%2FAllItems%2Easpx&ContentTypeId=0x01005772149CAE4E504CB575423DFD717194

page after:
&Source=http://---.---.---/sites/cgh/Steering/wgleads/ADS/Lists/Reports/AllItems.aspx&ContentTypeId=0x01005772149CAE4E504CB575423DFD717194

Looks like in modal approach by Russ, he is editing the form in the first step to add the link.  I cant use SPD in production. How do I put the link in the form client side?

 

Oct 25, 2012 at 5:54 PM

I commented on the other thread re: adding the link using script.

Just curious what would happen to the redirect if you changed spservices to not enclode the source url.

change this line:

   newHref += opt.newWindow ?
     ((opt.ContentTypeID.length > 0) ? "?ContentTypeID=" + opt.ContentTypeID : "") + "' target='_blank'" :
     "?" + ((opt.ContentTypeID.length > 0) ? "ContentTypeID=" + opt.ContentTypeID + "&" : "") + "Source=" + escapeUrl(location.href) + "'";
   

to this:

   newHref += opt.newWindow ?
     ((opt.ContentTypeID.length > 0) ? "?ContentTypeID=" + opt.ContentTypeID : "") + "' target='_blank'" :
     "?" + ((opt.ContentTypeID.length > 0) ? "ContentTypeID=" + opt.ContentTypeID + "&" : "") + "Source=" + location.href + "'";
   

Oct 25, 2012 at 7:38 PM

PS... if you're using localStorage, then try sessionStorage instead.  I don't know all the internals, but I think the former is available across sessions but is more dependant on the url while the latter is available on a single browser session across urls.  I could be wrong about that, but it's sessionStorage that works best for me in most cases.

Oct 25, 2012 at 8:03 PM

@jbooker Wrong! Both localStorage and sessionStorage work at the domain level. If you store data in MyTeam.MyCompany.com, it will be made available to all pages in MyTeam.MyCompany.com. The difference between the two is that the sessionStorage data will be erased when you close your browser.

Oct 25, 2012 at 8:08 PM

Well I was right about one thing: 'I could be wrong about that..' 

learn somthin new every day! cheers

sorry bcobra, sounds like the local storage prob has nothing to do with the url.

Oct 26, 2012 at 1:44 PM

@jbooker

$().SPServices.SPLookupAddNew doesn't use modals because of this reason:

"While this function works with SharePoint 2010, because of the modal dialogs the user will get "lost". Alternatively, if you've turned off the modal dialogs, the function works just great."

I was referring to this thread with my post as well. I meant to post it here. :)  I also meant that the problem stated in the docs with this function could probably be solved with my approach. Of course it'd have to work when modals aren't used or available, but I'm confident it's doable.


Cheers,
Matt 

Nov 1, 2012 at 6:38 PM

Just curious if my solution is worthy of a blog post. Really want something useful to blog about and thought this might make a good one. BTW, I was able to get local storage to work just fine though I did not need it for this.

Nov 6, 2012 at 9:17 PM

I created some javascript code that uses spservices to allow you to add a new item to a lookup list. When you return to the edit form the data already entered is still there and it also updates the lookup field with the value you just added to the lookup list.  It uses the Sharepioint 2010 dialogs, so it wont work on 2007 (although it could probably be retrifitted to use jquery dialogs)

I've been using the code in prodiuction for a while now, and its been working without any problem.

http://yetanothersharepointblog.wordpress.com/2012/11/07/adding-a-new-item-to-a-lookup-list-using-javascript-and-spservices/

Nov 6, 2012 at 11:39 PM

Interesting solution russgove, thanks for sharing.

Question:  Does it work with a multiselect look up?  It seems like it "selects" the newly added item from the drop down, so I'm assuming no?  If not, any knowledge on how to do so would be helpful.

Dec 6, 2012 at 8:41 PM
Edited Dec 6, 2012 at 11:36 PM

Toga,  No, it won't work for multi select. as is, but we could probably change it so that if the listbox was a multi select, we could append the new value to it

I'll did some digging...The Multi Select  displays two select boxes. The one on the left that holds the possible valuest has  a control title that ends wot the value "Possible Values". The one on the right has the selected items and it has a name that ends with selected values. (at least in my test site this is how it is ddisplaying, this may only be if there are more than 20 items. I think they changed tis in 2013 too!)

To make this work, all we would need to do woulneed to do, I think is to change the CounterpartAdded function  to find the select biox on the left using some jquery to find the title ending with  Selected valuess and append the new item to it.

Soomething like

function CounterpartyAdded(value, returnValue) {
    // if user canceled out of the add dialog
    if (value == '0') {
        return;
    }
    
    var lastItemID = $().SPServices.SPGetLastItemId({ listName: "Counterparties" });  // th id o fthe item just added
    var vendorDropDown = $("select[Title='Counterparty selected values']")[0]; // the dropdown on the right(the selected items)
    if (vendorDropDown !== null) {
        var myQuery = "" + lastItemID + "";

        $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "Counterparties",
            CAMLViewFields: "",
            CAMLQuery: myQuery,
            completefunc: function (xData, Status) {
                //	$(xData.responseXML).SPFilterNode("z:row").each(function() {  THIS IS THE SYNTAX FOR THE NEWWRE JQERY jQuery 1.7+,  with 
                $(xData.responseXML).find("[nodeName='z:row']").each(function () {
                   vendorDropDown.options.add(new Option($(this).attr("ows_Title"), $(this).attr("ows_ID")));
                   // if ($(this).attr("ows_ID") === lastItemID) {
                   //    vendorDropDown.options.add(new Option($(this).attr("ows_Title"), $(this).attr("ows_ID")));
                   //
                   // }


                });
            }
        });

    }
Feb 6, 2013 at 3:59 PM
First of all, I am not very code literate when it comes to scripts like this, so my question may be worded a little naively.

Is there a way within the exsisting SPLookupAddNew function to:
 Add a Save New Form command
 Run the SPLookupAddNew Function
 Re-direct to the default Edit Item Form
Thank you!
Brian
Coordinator
Feb 6, 2013 at 4:16 PM
Edited Feb 6, 2013 at 5:07 PM
Brian:

It's tricky because you can only save the current form if all of the required columns are already completed. Usually the lookup columns that you'd like to add values to tend to be toward the top of the form, so without ensurung that the user fills everything in first, it won't work. The UX for this just gets too clunky.

I originally built SPLookupAddNew just so I could add values in my testing, but it's taken on a life of its own.

M.
Feb 6, 2013 at 4:37 PM
Marc,

I could very easily understand that every single application has it's own caveats, and I certainly would never assume to ask for a custom solution to one set of circumstances.

Where would I go to find a list or directory of functions available within a custom form? My particular application has the lookups as option items at the end, so I am more willing to tinker than if it would completely negate the forms use.

Thank you
Brian S
Coordinator
Feb 6, 2013 at 5:08 PM
Brian:

All of the functions in SPServices are documented on the Documentation tab. Let me kbow if you have specific questions.

You can certainly borrow or clone any of the existing code - one of the joys of open source. If you come up with something you think might be of general use, please let me know.

M.
Feb 6, 2013 at 6:22 PM
Brian,
have a look at http://code.msdn.microsoft.com/Javascript-to-add-an-Add-60b6299b
and http://yetanothersharepointblog.wordpress.com/2012/11/07/adding-a-new-item-to-a-lookup-list-using-javascript-and-spservices/.
Its a solution that uses sharepoint Modals so You don't have to worry about saving your data.
Russell