1

My JS

for (var i=0; i<result.length ;i++) {

                var selectValue = $("#ProductCode option[value=" + result[i].PRODUCT_CODE + "]").text();

                html += '<tr id="tr-'+tblcounter+'" class=""><td class="pc">'
                           + selectValue
                           + '</td><td class="oc">'
                           + result[i].ORDER_QTY
                            + '</td><td class="oc">'
                           + result[i].DELIVERY_QTY
                            + '</td><?php if($usertype == "ANE"){?><td class="oc">'
                           + result[i].RECIEVED_QTY
                            + '</td><?php } ?><td class="operations"><a href="#" class="editlines" id="'+result[i].LINE_NUMBER+'" onClick="editRow(this);"><img src="<?php echo $this->baseUrl(); ?>/images/edit_icon.png" height="20px" width="20px"></a>'

                           + '</td></tr>';
                   tblcounter++;
              }
              $('#recvLines').append(html);

In the above table I need to display the last column if my Javascript condition satisfies, otherwise I dont want to display it.

For example

 + '</td><?php } ?>'+if("something" == "something")+'<td class="operations"><a href="#" class="editlines" id="'+result[i].LINE_NUMBER+'" onClick="editRow(this);"><img src="<?php echo $this->baseUrl(); ?>/images/edit_icon.png" height="20px" width="20px"></a>'

                           + '</td></tr>';

If I write the if condition like above the code is not working. Any ideas?? Thanks

1
  • php scripts will not be processed with in javascript Commented Jan 20, 2014 at 11:05

2 Answers 2

4

You can use ternary operator

+ '<tr>' + (x == 5 ? '<td>true</td>' : '<td>false</td>') + '</tr>'
Sign up to request clarification or add additional context in comments.

Comments

0
 + '</td><?php } ?>'+ ("something" == "something" ? '<td class="operations"><a href="#" class="editlines" id="'+result[i].LINE_NUMBER+'" onClick="editRow(this);"><img src="<?php echo $this->baseUrl(); ?>/images/edit_icon.png" height="20px" width="20px"></a></td>' : '') + '</tr>';

Might do the trick.

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.