I use a function to clear the input values of form fields in a container:
function clear_form_elements(ele) {
$(ele).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});}
this completely clears a set of input fields inside a div, fieldset or similar (defined as ele). Now I tried to replace the
$(this).val('');
with
if(this.id = "town") {this.val('town');}
if(this.id = "country") {this.val('country');}
to replace input elements with different IDs but the value returned for each input field is always “country” even though the ID of the element is different.
What am I doing wrong?
Change:
to
(double equals)
Your statement will always return true after setting values. you are trying to compare, not to set a value.