Jump to content
cosmin1987

Probleme Jquery

Recommended Posts

Salutare, am o mica problema, care este destul de simpla. Am urmatoarele checkbox-uri 

<input type="checkbox" class="add" data-amount="30"  id="extra_units_3" value="1" />
<input type="checkbox" class="add" data-amount="40"  id="extra_units_4" value="1" />
<input type="checkbox" class="add" data-amount="50"  id="extra_units_5" value="1" />
<input type="checkbox" class="add" data-amount="60"  id="extra_units_6" value="1" />

si imi calculeaza foarte simplu cu jquery : 

$('.add').click(function() {
    if($(this).is(':checked')) {
     $('#total').text(parseInt($('#total').text()) + parseInt($(this).data('amount')));
    } else {
     $('#total').text(parseInt($('#total').text()) - parseInt($(this).data('amount')));
    }
});

As vrea sa mai adaug un checkbox selected care sa nu poata fi modificat, care sa aibe data-amount="" stabilit de mine si apoi fiecare checkbox sa adauge valoarea (data-amount) peste valoarea checkbox-ului adaugat de mine.

 

Multumesc anticipat

Edited by cosmin1987
Link to comment
Share on other sites

Imi este neclara formularea

51 minutes ago, cosmin1987 said:

[...] adaug un checkbox selected care sa nu poata fi modificat [...]

Te referi sa fie checked si disabled? Adica asa?

<input type="checkbox" class="add" data-amount="1337" disabled="disabled" checked="checked">

 

  • Upvote 1
Link to comment
Share on other sites

Da corect hidden vreau sa il fac, dar din pacate am o problema, cand checkbox-ul se selecteaza incepe sa adune valorile de la data-amount, si as dorii sa pluseze suma checkbox-ului hidden 

 

<input type="checkbox" class="add" data-amount="1337" disabled="disabled" checked="checked">

adica sa imi adauge la 1337 valorile checkbox-urilor selectate.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...