0

I'm really struggling with this - have found a number of 'almost' answers but I cant quite get there!

I have a form with a select field (EventID) (This is a lookup from another table) that I want to choose the value of based on the query string,

eg: marketingpm/Lists/EventBudget/NewEventBudget.aspx?EventID=2

=> set the EventID field to 2

I can use

var itemID = GetUrlKeyValue('EventID'); 

to get the EventID from my URL (Yay)

Next I want to set the value using document.getElementByID() or something similar, but it doesn't seem to work

Here is my code in SharePoint Designer

<SharePoint:FormField runat="server" id="ff7{$Pos}" ControlMode="New" FieldName="EventID" __designer:bind="{ddwrt:DataBind('i',concat('ff7',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@EventID')}"/>

Here is the rendered code

<select name="ctl00$m$g_8c9a97e1_763c_44ad_8e92_cbe575864b0b$ctl00$ctl05$ctl06$ctl00$ctl00$ctl04$ctl00$Lookup" id="ctl00_m_g_8c9a97e1_763c_44ad_8e92_cbe575864b0b_ctl00_ctl05_ctl06_ctl00_ctl00_ctl04_ctl00_Lookup" title="EventID Required Field">

I've tried

document.getElementById("[title='EventID']").value = itemID;

document.getElementById("[title='EventID Required Field']").value = itemID;

document.getElementById("ctl00_m_g_8c9a97e1_763c_44ad_8e92_cbe575864b0b_ctl00_ctl05_ctl06_ctl00_ctl00_ctl04_ctl00_Lookup").value = itemID;

This one:

document.getElementById('<%=EventID.ClientID%>') = itemID;

gives me an error: Web Part Error: The 'Xsl' property of 'WebPartPages:DataFormWebPart' does not allow child objects.

In general my HTML and JavaScript is fair, but I just don't know enough about ASPX (or whatever the hell this is) to figure this out on my own. Any help or direction massively appreciated!!

I'm using Sharepoint 2010 (Free version), and Sharepoint Designer 2010

2
0

Thanks @Danny Engelman, this got me over the line

Solution in the end was:

var itemID = GetUrlKeyValue('EventID');
document.querySelector("[title='EventID Required Field']").value = itemID;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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