Reputation: 107
i m creating the python project i created the dropdown field in models.py ,then i have to display in html template . I have write the jquery code also.but dint work.
models.py
addtype = models.CharField(max_length=25,choices=STATE_CHOICES,default='seller')
forms.py
addtype = forms.ModelChoiceField(queryset=type.objects.all())
views.py
addtype = product_form.cleaned_data['addtype']
ad.html
<head>
<script src="../static/js/jquery-1.9.1.js"></script>
<script type="text/javascript">
alert("111");
$('#adtype').on('change', function() {
alert("aa");
var lb = $('#adtype').val();
if(lb = "seller")
{
aler("1");
$('#seller').hide();
$('#buyer').show();
}
else
{
$('#buyer').hide();
$('#seller').show();
}
});
</script>
</head>
<p>
{{ product_form.addtype.errors }}
<label>Type of Ad:</label>
<select name="ad"id="adtype">
<option value="seller">Seller</option>
<option value="buyer">Buyer</option>
</select>
</p>
<label id="seller"> Seller Information</label>
<label id="buyer" style="display: none;"> Buyer Information</label>
The above label want to change. if i click the seller, i want to change labale as seller infomration and vice versa
Upvotes: 0
Views: 227
Reputation: 9446
Assignment will always be evaluated as true:
if(lb = "seller")
Try
if(lb == "seller")
Upvotes: 0