user3507560 user3507560 - 1 year ago 87
jQuery Question

Jquery update ckfinder form field

I'm trying to update an input field value

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");

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';

<script src=""></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>

Answer Source

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' );

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download