0

I'm trying to get a button and for to appear or disappear depending on whether the list/ basket is empty or has at least one item in.

FIDDLE http://jsfiddle.net/amesy/vtg6nnce/16/

HTML...

<a href="#" class="send-order">Place your order</a>
<div class="form">
    <p>Form then appears somewhere</p>
</div>
<ul class="cbp-rfgrid biscuits clearfix">
    <li>
        <button type="button" data-biscuit="custardcream" class="biscuit custardcream">Custard Creams</button>
    </li>
    <li>
        <button type="button" data-biscuit="jammydodger" class="biscuit jammydodger">Jammy Dodger</button>
    </li>
    <li>
        <button type="button" data-biscuit="hobnob" class="biscuit hobnob">Hobnob</button>
    </li>
</ul>
<div class="barrel"></div>

jQuery...

$(function () {
    $('.biscuit').click(function () {
        $(this).toggleClass("selected");
    });

});

var barrel_items = [];

$('[data-biscuit]').click(function () {
    var biscuit = $(this).data('biscuit');
    add_to_barrel(biscuit);
});

function add_to_barrel(item) {
    if ($.inArray(item, barrel_items) !== -1) {
        return;
    }
    var name = '';
    switch (item) {
        case 'custardcream':
            name = 'Custard Creams';
            break;
        case 'hobnob':
            name = 'Hobnob';
            break;
        case 'jammydodger':
            name = 'Jammy Dodgers';
            break;
    }
    $('.barrel').append('<div class="chosen">' + name + '</div>');
    barrel_items.push(item);
    $('.send-order').toggleClass("show");
}

$(function () {
    $('.send-order').click(function () {
        //$(".selection").attr('src',"img/"+bicsuit+".jpg");
        //$(".basket ul").append('<li><a href="#"><img src="img/biscuit.jpg" class="clearfix"><div><h3>remove</h3></div></a></li>');
        $('.form').toggleClass("show");
    });
});

1 Answer 1

1

fixed it, i changed this $("#barrel").val(biscuit); to $("#barrel").val(barrel);

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

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.