1

I am looking to bulk-edit a column in JavaScript with the same numerical value and have the following code that will work if I use a hard-coded number, but I want to use a variable from a user input instead:

function changeValues()
{
var context = SP.ClientContext.get_current();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
var list = context.get_web().get_lists().getByTitle("ListTitle");
var item;
for (item in selectedItems)
{
var newValue = document.getElementsByName("htmlInput")[0]; //This is the value I want to use 
var myResItem = list.getItemById(selectedItems[item].id);
myResItem.set_item("ColumnName",newValue); //This is where hard-coded numbers work
myResItem.update();
}

I think I need to somehow format the "newValue" variable (SPFieldNumber?) but I have had no luck with my attempts thus far.

1 Answer 1

1

Here you are passing element.You have to pass value of this element.

myResItem.set_item("ColumnName",newValue.value); 

And do not forget to insert below code after myResItem.Update()

context.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFailed));

Also add following two methods

function onSuccess() {
    //alert message
}

function onFailed(sender, args) {
   //alert message
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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