user3507560 user3507560 - 1 month ago 13
jQuery Question

Jquery update ckfinder form field

I'm trying to update an input field value

.ckfinder-input
via ck finders pop up image selector.
It all works fine until I try and assign the selected image URL to the input field
input.val() = fileUrl
and get the following error message:


ReferenceError: invalid assignment left-hand side


Could someone shed some light on what I'm doing wrong?

My code is as follows:



$(".ckfinder-modal-button").on("click", function() {
input = $(this).parent().find(".ckfinder-input");
BrowseServer(input);
});

function BrowseServer(input) {
var finder = new CKFinder();
finder.selectActionData = input;
finder.selectActionFunction = function(fileUrl, data) {
input = data['selectActionData'];
console.log(input); //returns Object[input.form-control.ckfinder-input property value = "" attribute value = "null"]
console.log(fileUrl); //returns "/customer_images/header_images/home.jpg"
input.val() = fileUrl; // ReferenceError: invalid assignment left-hand side;
}
finder.resourceType = 'HeaderImages';
finder.removePlugins = 'basket';
finder.popup();
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="bootstrap-filestyle input-group">
<input type="text" class="form-control ckfinder-input" name="ckfinder-input">
<span class="group-span-filestyle input-group-btn ckfinder-modal-button" tabindex="0">
<label class="btn btn-default">
<span class="icon-span-filestyle fa fa-cloud-upload"></span>
</label>
</span>
</div>




Answer

probably it's because your JavaScript is invalid. You cannot assign a value (fileUrl) to the output of function (input.val()) in: js input.val() = 'abc'; You should either:

a) if it is DOM Input Element: input.value = 'abc';

b) if it's jQuery wrapper for DOM Element: input.val( 'abc' );