javascript - Add removeClass function in my Jquery -


i've been stuck problem more week -_-. need add removeclass function in jquery validation below. in bid , rfq validation add removeclass.

i have dropdown , 2 textbox (rfq , bid), when select bidding in dropdown bid textbox hide. problem when tried submit validation requirements comes out bcoz textbox bid doesn't have value. tried add removeclass function in textbox depends on dropdown value.

this working fiddle http://jsfiddle.net/mhck7/4/

part of validation jquery

if (bid == "") {     $("span.val_bid").html("this field required.").addclass('validate');     validation_holder = 1; } else {     if (!bid_regex.test(bid)) { // if invalid phone         $("span.val_bid").html("integer allowed!").addclass('validate');         validation_holder = 1;     }     else {         $("span.val_bid").html("");     } } if (rfq == "") {     $("span.val_rfq").html("this field required.").addclass('validate');     validation_holder = 1; } else {     if (!rfq_regex.test(rfq)) { // if invalid phone         $("span.val_rfq").html("integer allowed!").addclass('validate');         validation_holder = 1;     }     else {         $("span.val_rfq").html("");     } } 

remove class jquery

$('#txt1').change(function () {     if ($(this).val() == 'negotiated' || $(this).val() == 'shopping' || $(this).val() == '') {         $("#txt2,#txt3").val('');         $("#txt2").removeclass("mandatory");         $("#txt3").removeclass("mandatory");     }     else if ($(this).val() == 'bidding') {         $("#txt3").val('');         $("#txt3").removeclass("mandatory");     }     else if ($(this).val() == 'rfq') {         $("#txt2").val('');         $("#txt2").removeclass("mandatory");     }     else {         //here can specify if value not negotiated or shopping     } }); 

i might take stab on one. in bid_rfq() have hide/show functionality of input fields. else add/remove mandatory class input fields ones should/shouldn't have it. ie:

function bid_rfq() {     if($("#txt1").val() =="bidding"){         $("#bid").css({visibility:'visible', overflow: 'visible'});         $("#txt2").addclass("mandatory");         $("#rfq").css({visibility:'hidden', overflow: 'hidden'});         $("#txt3").removeclass("mandatory");     if($("#txt1").val() =="rfq"){         $("#bid").css({visibility:'hidden', overflow: 'hidden'});         $("#txt2").removeclass("mandatory");         $("#rfq").css({visibility:'visible', overflow: 'visible'});         $("#txt3").addclass("mandatory");     } else {         $("#bid").css({visibility:'hidden', overflow: 'hidden'});         $("#txt2").removeclass("mandatory");         $("#rfq").css({visibility:'hidden', overflow: 'hidden'});         $("#txt3").removeclass("mandatory");     }     return true; } 

so find out if each input required when doing validation. simplicity, can even:

var rfq = $("form#register_form input[name='n_rfq']").val(); var rfq_regex = /^[0-9\-]+$/; // reg ex qty check var rfq_mandatory =  $("#txt3").hasclass("mandatory"); var bid = $("form#register_form input[name='n_bid']").val(); var bid_regex = /^[0-9\-]+$/; // reg ex qty check var bid_mandatory =  $("#txt2").hasclass("mandatory"); 

so when doing validation, can:

if(bid == "" && bid_mandatory) ,  if(!bid_regex.test(bid) && bid_mandatory) 

js fiddle can found here.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -