Reputation: 2349
I have two fields that usually work as they should and submit. their IDs and names are 'location_names' and 'sub_cat'
My script is complete except for the fact that I want the 'sub_cat' field value to be ignored (it is completely ignored now) only when the value is '-10' and for it to replace 'location_names' if the value IS NOT '-10'. I had several failed attempts at doing this, all of them just ignore the values or return null. I wonder if I should use regular javascript instead? Any help at all is appreciated.
Code description:
onSubmit{
if (sub_cat != '-10') {
location_names.value = sub_cat.value;
}
else {
// do nothing
}
}
Upvotes: 1
Views: 374
Reputation: 11281
I suppose sub_cat is the element, i.e, sub_cat = $('#sub_cat');
In this case:
onSubmit {
if (parseInt(sub_cat.val(), 10) != -10)
location_names.val() = sub_cat.val();
// Add this if you don't want to submit the form when the value is -10.
return false;
}
Upvotes: 0
Reputation: 362
You mean something like this?
Upvotes: 1
Reputation: 14282
I guess you should some thing like below when caparisoning of numbers in JS
if (parseInt(sub_cat, 10) != -10) {
location_names.value = sub_cat.value;
}
Hope this will help you.
Upvotes: 0