jquery - Force invisible text fields to have a value of "0" or "" -


i know kind of cludgey, close solution had post this.

i have form 2 checkboxes toggle whether or not relevant spans visible. num_bw , num_c spans contain input boxes user puts how many of 2 types of products user wants. worried, though, user might put number text field that's temporarily visible (say first one, in num_bw span), change mind , uncheck check box , put number box in num_c span instead.

the way code works, num_bw field invisible- still contain number! if hits submit, user might surprised see 3 black & white products no longer wants still in shopping cart! woops!

so need check if of these 2 text fields (their names orderquantitybw , orderquantityc, can add id's if need to) in span invisible (#num_bw , #num_c), , if are, turn value nothing, zero, zilch, "", whatever won't confuse shopping cart software (which isn't department, how works tad opaque me.)

this in head, makes these spans invisible @ start:

    $(document).ready(function() {     $('#num_bw').hide();     $('#num_c').hide();     }); 

this right after form in question, makes spans visible or invisible when user clicks on checkboxes:

$('#show_c').click(function(){ $('#num_c').toggle(); }); $('#show_bw').click(function(){ $('#num_bw').toggle(); }); 

and want add function end. stopped short of writing it. help?

    $('#submit_btn').click(function(){      /*insert script turn form box's values "0" if      in invisible span*/      )}; 

try this

$('#submit_btn').click(function(){      $("#num_bw, #num_c").each(function(){        if(!$(this).is("visible")){          $(this).find("input").val("0")        }     });  )}; 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -