CRM has a quite cool feature that can save you a lot of programming: URL addressable forms. If you want to let users create or update records, you can use the CRM standard forms. The only thing you have to do: open an new window with the specific URL. If you want to edit a record, you only have to append the id of the specific record. In edition you are able to manipulate every form field in the new window and pre-fill them. (I do not mention x-domain-scripting here).

If you want to manipulate lookup fields, you have to do this in a special way to make it work. I did not find it anywhere, so I will post here how to do it. Just look at the following JS snippet to figure out how. In the following example the source campaign of a new lead record is pre-filled:

var newwin;

// first you have to open an new window. call the following function from anywhere on your web page
function OpenNewLead()
{
 newwin=window.open('/sfa/leads/edit.aspx', 'newlead',
  'width=830,height=600,directories=no,menubar=no,resizable=yes,titlebar=no,toolbar=no');
    
 window.setTimeout("PreFillSourceCampaign()", 1000);
}

function PreFillSourceCampaign()
{
 if(!newwin.document.crmForm.all.campaignid.DataValue)
 {  
  var ar=new Array(1);
  ar[0]=new Object;   
  ar[0].id='{00000000-0000-0000-0000-000000000000}'; // fill in here the correct GUID of your object
  ar[0].type='4400'; // adapt the typecode for your entity type
  ar[0].name='My Campaign Name';   // adapt the correct object name
  newwin.document.crmForm.all.campaignid.DataValue=ar;
 }
 else
 {
  window.setTimeout("PreFillSourceCampaign()", 1000);
 }
}

P.S. I use window.setTimeout here to make sure the DOM of the new child window is loaded before I manipulate the field.

Have fun! :-)