tags:

views:

55

answers:

1

These fields are hidden correctly, but what is the best way of setting the hidden field values.

$j.registerType = {
    '' : $j([]),
    'srotc_cadet' : $j('#vm_schoolstate_divContainer,#vm_srotcschool_divContainer,#vm_mslevel_divContainer'),
    'srotc_intructor' : $j('#vm_schoolstate_divContainer,#vm_srotcschool_divContainer'),
    'jrotc_cadet' : $j('#vm_highschool_divContainer,#vm_highschoolstate_divContainer,#vm_highschoolcity_divContainer')
  };

  $j('#vm_registertype').change(function() {
    // hide all
    $j.each($j.registerType, function() { this.hide(); });
    // show current
    $j.registerType[$j(this).val()].show();
  }).change();


  $j('#vm_registertype').change(function() {
   var regType =  $j('#vm_registertype').val();
   switch (regType) { 
   case "srotc_type":
    $j('#vm_highschool_field,#vm_highschoolstate_field,#vm_highschoolcity_field').val("DOES NOT APPLY");
    break;
    }

   }).change();


I just notice the "srotc_type" error. changed it but the code still doesn't work....

+1  A: 

Looks like your objective here isn't what your question is asking (how to set a hidden input's value), but to do with what you should set the value to when you've taken it out of the form. How about, then, instead of putting wacky things in the value, you do:

$j.each($j.registerType, function() {
    this.find(':input').attr('disabled', true); 
    this.hide();
});

This will prevent any value from being sent for those inputs when the form is submitted.

chaos
Thanks for answering chaos, the problem is that I'm hiding the container holding the fields.. Is there a way to find the input elements in $j.each($j.registerType) and set the disabled value....This what's happening with your code:<div id="vm_highschool_divContainer" disabled="true" style="display: none;">
Sure, edited per.
chaos
This is partially working...The disabled value is added to all the elements.
What isn't working?
chaos
the code is also disabling everything but the registerType select. I only want the hidden fields to be disabled withing each container.