2

In my application I am trying to hide a table based on a condition. I am using simple javascript function to hide the table.

the function is failing on the following line

if ((image1.trim() = '') && (image2 != '1')) {

giving error

'Microsoft JScript runtime error: Cannot assign to a function result'.

Here is the code.

Html code:

 <table id="tblImage" cellpadding="0" cellspacing="0" style="padding:2px 0px">
            <tr>                
                <td>
                    <div id="otherImages"></div>
                </td>
            </tr>
     </table>   

Javascript function:

function DisplayTable() {
    var image1 = document.getElementById('ctl00_ContentPlaceHolder1_image1').value;
    var image2 = document.getElementById('ctl00_ContentPlaceHolder1_image2').value;
    if ((image1.trim() = '') && (image2 != '')) {
         jQuery('#tblImage').hide();
    }
}
1
  • = is not the same as == ;) And to push it one step further. Keep using the strict versions of the comparison operators link :) Commented Sep 4, 2012 at 16:11

3 Answers 3

4

You are using =, but you should use ==:

if ((image1.trim() == '') && (image2 != '1')) {

Basicaly = means assign value and == means is equal to. This generates error because it is not possible to assign value to function (which happens where, you're trying to assign value to trim()).

Sign up to request clarification or add additional context in comments.

Comments

2

if ((image1.trim() = '') && (image2 != '')) {

should be

if ((image1.trim() == '') && (image2 != '')) {
              this__^

Comments

2

You are using = (assignment) instead of == (equals) in the folowing if statement, resulting in the assignment to a function error. Use the following instead:

if ((image1.trim() == '') && (image2 != '')) {
     jQuery('#tblImage').hide();
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.