I need jquery code which can copy the data from one column(look up column) and populate into other column (single text line) in the same list in sharepoint 2010.
2 Answers
If you really need to implement such a copy mechanism using javascript you can use the javascript Client Script Object Model also called JSOM for this task. You can find a description and examples here: https://msdn.microsoft.com/en-us/library/office/hh372944(v=office.14).aspx Using JSOM will only work if you're calling that script from within SharePoint.
Should you need to execute that script outside of that SharePoint site, you could use the SPServices library which uses SharePoint webservices in the background: http://spservices.codeplex.com/
May I ask what the purpose of this copy is though? Depending on what you need it for, you could also just use a calculated column to "display" the value of the other column, but I also wouldn't see much purpose of that. :)
-
Thanks for this info. I dont have much idea on code, so tries the codes provided in the link by just replacing the column name and ID to mine one, but it didnot work. I can do this by using calculated column but that will not resolve my issue.Kanan– Kanan2015-08-05 12:44:00 +00:00Commented Aug 5, 2015 at 12:44
-
What is the issue you're trying to solve by this?Swiss Dev– Swiss Dev2015-08-05 12:44:54 +00:00Commented Aug 5, 2015 at 12:44
-
Actually I am doing color coding in sharepoint 2010 with help of calculated columns. The colors to be selected based on value of a lookup column. As I am not able to select lookup column in calculated column formula, I need some jquery which will copy data from my lookup column and paste into another single text column. And that text column I can use for my calculated column. Could you please help me with the jquery code?Kanan– Kanan2015-08-05 12:47:29 +00:00Commented Aug 5, 2015 at 12:47
-
Note: I dont have sharepoint designer not PowerShell scriptKanan– Kanan2015-08-05 12:48:13 +00:00Commented Aug 5, 2015 at 12:48
-
Ah! If you're gonna use jquery already, just do the color coding with jquery, based on the value of the lookup column. This will be straight-forward and would make more sense, rather than making a copy of the field and then using the calculated column.Swiss Dev– Swiss Dev2015-08-05 12:49:24 +00:00Commented Aug 5, 2015 at 12:49
This should do it:
function PreSaveItem() {
var N1 = $("select[title$='LookUpField'] option:selected").text();
$ ( "input[title='SingleTextField']").val(N1);
return true;
}