0

I'm trying to delete selected objects out of input Costs and Names. Using deleteObject button. But I don't know how, is there the way to do this?

 <canvas id="c" width="780" height="720" style="border:1px solid #aaa"></canvas>
 <img class="items_img" src="photo/images.jpg"  data-type="500" data-name="photo1" />
 <img class="items_img" src="photo/images1.jpg" data-type="2000" data-name="photo2" />
 <img class="items_img" src="photo/images2.jpg" data-type="3000" data-name="photo3" />
 <p class="btn btn-primary" onClick="deleteObject()">Delete</p>
 <strong>Costs </strong>: <input type="text" name="cost" id="cost"/>
 <strong>Names </strong>: <input type="text" name="name" id="name"/>

This JavaScript code.

function deleteObject() {
canvas.getActiveObject().remove();
discost.push(z1[0]);
console.log(discost); 
}

function addAllToCanvas() {
check3 = 1;
var i;
for (i = 0; i < elements.length; i += 1) {
    canvas.add(elements[i]);
}

This Jquery code.

    var totalprice= 0;
    var totalname = [];
$(document).ready(function(){
        $('.items_img').click(function(){
      var name = $(this).attr('data-name');
            totalname.push(name);

            if (totalname == ''){
              $('#name').val('');
            } else {
              $('#name').val(totalname);
            }

var price = $(this).attr('data-type');           
            totalprice = totalprice + parseInt(price);  

             if (totalprice == 0) {
                $('#cost').val('');
             } else {
                $('#cost').val(totalprice);
             }
            }
};
Max Kasem
  • 79
  • 9
  • Where is `canvas` defined? – jmargolisvt Dec 25 '17 at 13:57
  • @jmargolisvt I took the canvas out – Max Kasem Dec 25 '17 at 15:09
  • 1
    Why did you do that? I was referring to the `canvas` in your JS function. It doesn't refer to anything unless you've defined it somewhere else not shown here. Are you using fabric.js? – jmargolisvt Dec 25 '17 at 15:12
  • yeah i'm using fabric.js. – Max Kasem Dec 25 '17 at 19:54
  • @jmargolisvt now i'm fixed it. can you be able to help me? – Max Kasem Dec 25 '17 at 20:07
  • 1
    You still haven't answered my first question. See this very similar question: https://stackoverflow.com/questions/31727049/let-user-delete-a-selected-fabric-js-object You need to have something like `canvas = new fabric.Canvas('canvas');` for starters. That is relevant code that should be included here. Otherwise, it's undefined and nothing will work. Do you have a console error? – jmargolisvt Dec 25 '17 at 20:16
  • no its work perfectly fine – Max Kasem Dec 25 '17 at 20:23
  • 1
    Please host a simple demo where issue can be reproduced – user700284 Dec 26 '17 at 04:09
  • This is confused. What do you exactly want to achieve ? Delete objects from canvas depending on their id ? This `selected objects out of input Costs and Names` really bugs me. – Mozgor Jan 02 '18 at 16:49

0 Answers0