I tried to like this but still got problem. I think Only thing to do more
is "How can I link the price value to check option's value?"
What is wrong? (It's still tough to the newbie.)
**** javascript* I put on html file.
<script>
$(document).ready(function() {
$("input").click(function(event) {
var total = 0;
$("input:checked").each(function() {
total += parseInt($(this).val());
});
if (total == 0) {
$('#TotalCost').val('');
}
else {
$('#TotalCost').val('$' + total);
}
});
});
</script>
*** I changed the code in *single.html *as below
<select class='form-control' name='price'>
{% if product.choice_set.all %}
{% for item in product.*choice*_set.all %}
<option *value*='{{ *item.price*|lower }}'>{{ item.name }}{{
item.price|capfirst }}Add price </option>
{% endfor %}
</select>
<p>*Total Choice's Amount* : <input type="text" name="TotlCost"
id="TotalCost" size="10"/></p>
{% endif %}
2015년 1월 6일 화요일 오후 5시 4분 46초 UTC+9, rdyact 님의 말:
>
> Oh, thanks a lot, I'll try it anyway. ~~
>
> 2015년 1월 6일 화요일 오후 12시 45분 49초 UTC+9, Collin Anderson 님의 말:
>>
>> Hi,
>>
>> You probably need to use javascript to make the total price auto-update
>> when you check or uncheck each box. Check out jQuery if you haven't.
>>
>> Once you have that, then, yes, you'll want to re-calculate the price in
>> django to be sure it's correct.
>>
>> You could create an Order or Cart model that stores which (or how many of
>> each) items have been select, and maybe the total price too.
>>
>> Collin
>>
>> On Sunday, January 4, 2015 12:55:02 AM UTC-5, rdyact wrote:
>>>
>>>
>>> <https://lh3.googleusercontent.com/-CmnYqbBB-ws/VKjVXOH24II/AAAAAAAAHQw/0zYR1Des11Y/s1600/checkbox%2Boption.png>
>>> I want to program to calculate sum of user sleclecion of options with
>>> checkbox.
>>> Pls help me how to keep away from this suffer.
>>> I summarize what I want to do in my attached ppt file.
>>>
>>> How can I code for this in my viws.py & models.py each?
>>>
>>>
>>> #Product&Choice Model - models.py
>>>
>>> class Product(models.Model):
>>> title = models.CharField(max_length=120)
>>> description = models.TextField(null=True, blank=True)
>>> price = models.DecimalField(decimal_places=0, max_digits=100,
>>> default=10000)
>>>
>>> class Choice(models.Model):
>>> product = models.ForeignKey(Product)
>>> name = models.CharField(max_length=255)
>>> price = models.DecimalField(decimal_places=0, max_digits=100, default=0)
>>>
>>> # single.html
>>>
>>> <p>Your Product Price : {{ product.price }}$</p><hr/>
>>>
>>> {% for item in product.choice_set.all %}
>>> <form method='POST' action=''>{% csrf_token %}<input type='checkbox'
>>> value='{{ item.id }}' name='choice'> {{ item.name }} : {{ item.price
>>> }}$ <br/>
>>> {% endfor %}
>>> <input type='submit' value='submit'>
>>> </form><hr/>
>>> ~~
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/5ea9ef49-5f19-4bdf-adc5-fe71f7e5dd90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.