.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Set Default Value of BDC Field with Javascript

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :SharePoint
I have customized a newform.aspx page for a list. The form has a couple of BDC fields, one of which I'm trying to set a default value. I have a javascript using jquery that sets the default value of several regular text fields but I cannot get the function to work with the BDC field. I have the following code:
function setDefault() {
var variety = "blue";

var elem = getBDCTagFromIdentifierAndTitle("TEXTAREA","Object Picker", 1);
if(elem) elem.value = variety;
var elem = getBDCTagFromIdentifierAndTitle("DIV","Object Picker", 1);
if(elem) elem.innerText = variety;


function getBDCTagFromIdentifierAndTitle(tagName, title, count) {
  var tags = document.getElementsByTagName(tagName);
  var myCount = 0;
  for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;
    if (tags[i].title == title){
      if(count == myCount){
        return tags[i];
  return null;
This shows the value in the field, but when I save the form, the field does not save the value. My regular text fields that have a default value set do save, just not the BDC field. I've verified that the getBDCTagFromIdentifierAndTitle function does return valid objects and their value/innerText are indeed being set.

Any suggestions? is there a better way of setting the default v

View Complete Post

More Related Resource Links

Mission Impossible? Use Javascript to Disable a Multi-Line Rich Text Field


Hey Community,

Here's a tough one that I have struggled with and so far have not been able to find an answer for - how do you use Javascript to disable a multi-line rich text field.  I have customized a SP Edit form by adding a CEWP.  In the CEWP I have added the Javascript below (only a partial code sample provided) to disable several fields in the form.  The code works fine for single line text fields but it does not work for multi-line rich text fields.  Any suggestions?

<script language="javascript">
//This runs the function when the form first loads

//This locks the fields the users should not modify
function lockFields()
  var theInputTFTitle = getTagFromIdentifierAndTitle("Input","TextField","Title");
  theInputTFTitle.readOnly = true;
  theInputTFTitle.style.color = 'gray';
  //alert(" Value: " + theInputTFTitle.value);//for testing

   var theInputDDLReplyStatus = getTagFromIdentifierAndTitle("select","DropDownChoice","Reply Status");
  theInputDDLReplyStatus.disabled = true;
  //alert(" Value: " + theInputDDLReplyStatus.value);//for testing

  var theInpu

modify/override properties of default sharepoint modal dialogs (ex. editview.aspx) using javascript

Hello all, I would like to know how can I modify (override) some properties of the default sharepoint modal dialogs using Javascript. Ex. the size and location of editview.aspx. I while ago I asked a question about overriding the DialogResult in the display view dialog. I got an answer from Zach which looked like this:             sb.Append("<script type=\"text/javascript\">");             sb.Append(@"window.setTimeout(function () {");             sb.Append(@"if (window.frameElement && typeof(window.frameElement.overrideDialogResult) == 'function')");             sb.Append(@"{");             sb.Append(@"SP.SOD.executeFunc('sp.ui.dialog.js', 'SP.UI.DialogResult.OK', function () {");             sb.Append(@"window.frameElement.overrideDialogResult(SP.UI.DialogResult.OK); ");             sb.Append(@"});");             sb.Append(@"}");  

Can I update Project Field value via some javascript?

Hi there, I've a webpart that's designed to update some project field value, this webpart is  located on a Project Details Pages. On this project details page, there is another MS Build-in webpart call Project Field webpart. Now when I clicked the Save ribbon button, the project field webpart will raise some client calls, at the same time my custom webpart will raise a post-back(update value via PSI) call which will kill the client calls..So is it possible for me update the project filed value via some javascript? so I'll no longer raise a postback. Or is it possible for me to capture the client calls event for MS webpart, then I can fired my own PSI code? Thank you,   Regards, Joe

javascript for field validation on a textbox...

I'm looking at doing the validation for the email in javascript since we have asp.net 1.1. I can get it to just alert fine, but once I add the return validation it doesn't fire. Me.ImageButton2.Attributes.Add("onclick", "return validation(this);") <script language="JavaScript"> <!-- function validation () { var test=""; test = document.ticketForm.emailAddress.value; if (test == "xyz") { alert(test); return false; // validation failed } --> </script>

Passing hidden field ASP.net to javascript

Hi!   I have in my project an button that when is press need to verify if the aplication has been save. If the app no save, then popup a message (confirm box) to ask user yes or no to continue.   Hi have in my asp code a hidden field that gives me if the app is saved ou not, and I have this javascript function that I atach to my button onclientclick function.  <asp:HiddenField ID="HIdCab" runat="server" />    <asp:Button ID="BtnRetomar" runat="server" CausesValidation="False" CssClass="botao" Text="Retornar" Width="85px" onclientclick="" />   <script type="text/javascript" language="javascript">function MyRetornar(){    var myId = document.getElementById("<%=HIdCab.ClientID%>");                if (myId==null)    {               return confirm('Quer retornar SEM GRAVAR a aplicação actual?');   }    else    {        return true;     }}                   <

Set the DateTime field using javascript

Hi everyone, I need Help in implementing a solution. I have 2 fields: Resolution Date (DateTime) and Severity (Dropdown) and I need depending on the choise in dropdown (0-3) set different dates into the DateTime field. The difficult part is that I can't realize how is to SET the date there %) Here is my code: var ExpDateResolved = $("input[title=Expected Resolution Date]").first(); $("select[title=Severity]").first().change(function(){ ExpDateResolved.val(''); var chbReqSevDom = $(this).get(0); if (chbReqSevDom.selectedIndex == 0)  //first value in dropdown selected { var currentDate = new Date(); DateResolved.val(zeroPad(currentDate.getDate(),2) + '.' + zeroPad((currentDate.getMonth()+1),2) + '.' + currentDate.getFullYear()); } } P.S. I've tried to set a date into a Text field and it works.

Javascript price update ...hidden field ... asap

Hello Experts http://store.apple.com/us/configure/MC374LL/A?mco=MTc0Njg1ODA Like in this link i created a javascript function  === id , lenght , width , dept , capacity ,price ..<script type="text/javascript">function getproductdetail (id,len,wid,dep,cap,thick,prc)     {          document.getElementById('row1')=prc   }          </script>the same function is called at a new place where i pass only price .. i have to check if there is a price is present in 'row1' i have to add new prc to present one .. =================== thing is where i will retain the old value present .. How to check whether value is prsent in row1 or not ..... if i will choose hidden field where to use and how to check value for that ... Thanks

Adding JavaScript to Default.aspx


Hi there,

I am relatively new to SharePoint Designer and want to add a piece of JavaScript code that I have used before on standard HTML websites but I am not 100% sure where to put the code on the page.

I tried already and got an error so I have removed the code and the page works as standard.

Below is the code I inserted to a webpartzone (right) replacing the &nbsp; which was already there.

<script type="text/javascript">
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
new fadeshow(fadeimages, 300, 220, 0, 7000, 1)

The main script is very long so I hadnt pasted it in but i placed it at the top of the page (when in code view). Here it is below:

What am i doing wrong?

The Commish

<script type="text/javascript"> 
* Ultimate Fade-In Slideshow (v1.5): © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages[0]=["images/rotate01.jpg", "", "

error calling javascript in grid view template field


I am using a asp link button in grid template field which calls a pop up,i need to find the link button's control in cs page.

my link button code

<asp:LinkButton runat="server" ID="hlQName" Text='<%# Eval("QuestionnaireName")%>' OnClientClick

Onchange event for datetime field in javascript is not working?


I want to compare start date and end date when start date is changed. If start date is big, on change event i need to make the end date the same as start date.

So I wrote On change event for start date. But it doesnot work  

getField('input','Start Time').onchange = function() {showEndDate()};


function showEndDate()



var date1 = getField('input','Start Time');

var date2 = getField('input','End Time');


but its not firing at all. So you guys have any idea or any other way to do for datetime on change event?

filling current user name in people picker field when loading form using javascript


Hello guys,

I am looking is there any way to fill the current user's name in people picker field in newform.aspx using javascript?

If you anything, please let me know 


javascript alert window when dropdown field is selected,



is there a way..where an alert window prompts up to remind the user to select a checkbox when one field in dropdown is selected..for example

there is a dropdown field(Status)  which contains (Tobe confirmed, confirmed and rejected ), when confirmed is chosen..an alert window prompts up reminding the user to select a checkbox(send email) - Yes or No. It is not compulsory for the user to select the checkbox, but if Yes is chosen, the workflow will send an email

getting time and date from datetime field in javascript


Hello guys, I need to get hours from the difference between two datetime fields. I wrote the javascript which will get the date from datetime field.

But its not getting the correct time that entered on date time field. Its defaultly getting the current time on my system.

So do you guys have any idea. How to get time from date time fields. and how calculate hours between two datetime fields using javascript.

"Person or Group" Field Default Value



I have a "Person or Group" column being used to indicate an Assigned To value for our application. I would like the value of that column to default to the current user's name - in other words, the person submitting the new list item will be the assignee by default (and has the option to change it).


I tried doing this through SharePoint Designer by placing [Me] in some value attributes, but it's not working.


Is there some way to accomplish this?






How to delete the default columns( All day Event field ) from the Calendar List in sharepoint?



Is there anyway of disabling the All day Event field in a Calendar list. I don't have the option to hide it either.

Any help appriciated...


Srikanth Reddy

assign default value to dynamic data field



I have the script below and I want to apply a default value to the DynamicField StudentId (please see line in bold) below. Can anyone tell me how to do so?




        <asp:GridView ID="GridViewGuardians"  runat="server" SelectedIndex="1"
            AutoGenerateColumns="false" DataKeyNames="StudentGuardianId" DataSourceID="LinqDataSourceGuardians" ShowHeader="true" ShowFooter="True">
                   <asp:LinkButton  ID="lbInsertGuardianG" runat="server" CommandName="Insert" ValidateionGroup="addValidationGuardian" OnClick="lbInsertGuardianG_Click" >Insert</asp:LinkButton>

adding javascript breaks default page layout in vwd 2010


I'm putting together my first project in vwd 2010 and I'm starting with the default settings for a web form project.  I'm trying to add an external js file to a content page that inherits from the default master page.   When I add my .js file to the page, the navigation links, which normally display horizontal, desplay like a vertical list.  If I comment out the code then it displays ok.  

Here's how I'm adding my file in the code behind:

    protected void Page_Load(object sender, EventArgs e)
        if (!ClientScript.IsClientScriptBlockRegistered("getNewWord"))
            ClientScript.RegisterClientScriptBlock(this.GetType(), "getNewWord",
            "<script language=javascript src='Scripts\\getNewWord.js'>");   

 The navigation markup in the master page looks like this:

            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                        <asp:MenuItem NavigateUrl="~/Home.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend