views:

69

answers:

3

Total N00b here, I have a long form wizard that needs one step to be dynamically shown/hidden dependant on a radio button. All is cool with the code thus far.

function checkRb () {
      if($(this).is(":checked")){
      //yes
      $("#do_frick").val("step5");
      //alert ("yeah");
      }else {
      //no
      $("#do_frick").val("submit_step");
      //alert ("no");
      }
      }

The issue is that the hidden field "#do_frick" is several steps further down the page. If I place it in the same div as the checkbox, values change no problem. Place "#do_frick" further down the form and it doesnt change.

I expect that $(this) is only looking inside the current div and not the entire document. I got this far with the help of a very good programmer and dont want to annoy him further with N00b questions, any help greatly appreciated :)

It appears that if I put the "#do_frick" inside a div that is further down the page the form wizard sets the to display:none and anything inside the div cannot be set... would this be correct ?

+1  A: 

Please view source of your page to check what is ID of hidden field when it is several steps down. If ID is same then position should not be a problem.

this is not current div. In event handlers it means the object that raised the event. You should check jquery.com for more information on this.

PS:- try setting value of hidden field like this

 $("#do_frick").attr("value","submit_step");
TheVillageIdiot
A: 

look for the id in generated html as suggested above.

Also look for any duplicate id shared by any other element, this will mess up things.

Nrj
Is there any chance that the hidden field I am targeting is in a <div> that has the inline style "display: none;" applied by the form wizard ?
Stuart
It wont be visible, but yes the duplicate id will definitely conflict.Use unique ids where ever possible.
Nrj
A: 

SO after much noodle scratching the answer is a little bug/hiccup in jQuery

Whenever the field is in a div that has the rule "dsiaply: none;" applied jQuery cant reach inside and change it. Checking with firebug, the field has an additional value "disabled=''". Using the command

$('#do_frick').get(0).disabled = false

Sorts it out.. finally:)

Final code:

function checkRb () {
      if($(this).is(":checked")){
      //yes
      $('#do_frick').get(0).disabled = false //The important bit
      $("#do_frick").val("step5");
      //alert ("yeah");
      }else {
      //no
      $("#do_frick").val("submit_step");
      //alert ("no");
      }
      }
Stuart