Uncaught ReferenceError: Invalid left-hand side in assignment


#1

I am trying to use the following fiddle in my code with few differences :

The HTML is :

<div class="col-md-6">
				<div class="inputBtnSection">
				    <input id="uploadFile" class="disableInputField"  placeholder="Hi"  disabled="disabled" />
						<label class="fileUpload">
							<input id="uploadBtn" type="file" class="upload" />
							<span class="uploadBtn">Upload / Browse File ..</span>
						</label>
				</div>
	</div>

In Javascript, since I have to use jQuery 1.6.1, the on method/function doesn't work and hence I am using live as shown below:

$('.fileUpload').live('click','.fileUpload',function()
{ 
    //alert("The text has been changed."); // this works fine if I uncomment it
	$("#uploadFile").val() = this.val();
});

When I click on Upload/Browse File, I get Uncaught ReferenceError: Invalid left-hand side in assignment error in the console. Please let me know what am I doing wrong here? Thanks


#2

At the jQuery val documentation page you will see that assignment isn't used.


#3

Thanks. What would be a good strategy to replace this part of the JSFiddle:

document.getElementById("uploadBtn").onchange = function () {
    document.getElementById("uploadFile").value = this.value;
};

with the jQuery using correct val() in my case:

$('.fileUpload').live('click','.fileUpload',function()
{ 
    //alert("The text has been changed."); // this works fine if I uncomment it
	$("#uploadFile").val() = this.val();
});

Should I just change $("#uploadFile").val() = this.val(); to $("#uploadFile").val() ?


#4

No, you should put what you want to assign to the upload file value inside of the parenthesis.


#5

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.