lundi 4 juillet 2016

SharePoint add javascript event to a editForm.aspx page


I have a Sharepoint list where I want to customize the editForm.aspx page with javascript. The problem is that I can't manage to add any events to the controls in that page. I am able to get a reference to my control with this code: var textarea1; var objForm = document.forms[0]; function FindField() { var title; title= $().SPServices.SPGetDisplayFromStatic({ listName: "MyList", columnStaticName: "mycolumn" }); textarea1 = ChooseFieldByTitle("TextField", title); } function ChooseFieldByTitle(TypeField, title) { var elem; for (idx = 0; idx < objForm.elements.length; idx++) { elem = objForm.elements[idx]; if (elem.id.indexOf(TypeField) != -1 && elem.title == title) { return elem; } } return null; }; This runs fine but I can't attach any event on this control. I have tried the following code (Field is a textArea): Field.attachEvent("onchange", myFunction); Field.addEventListener("onchange", myFunction, false); Field.onchange = myFunction() {}; When I change the content of the textArea nothings happen. When I debug with IE developpers tools "myFunction" is never called. What am I doing wrong? I have look at SPServices JQuery library but nothing seems to be related to javascript events. Doess anyone Have a clue? thanks a lot.

Aucun commentaire:

Enregistrer un commentaire