Geetha
Geetha

Reputation: 107

how to change the label value after i selected dropdown

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

Answers (1)

zxzak
zxzak

Reputation: 9446

Assignment will always be evaluated as true:

if(lb = "seller")

Try

if(lb == "seller")

Upvotes: 0

Related Questions