1

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 ?

2
  • What other thing are you using? Like PHP, asp.net, plain html or what? Commented Jun 29, 2009 at 3:13
  • PHP based but testing is only on HTML Commented Jun 29, 2009 at 8:01

3 Answers 3

1

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");
Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

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 ?
It wont be visible, but yes the duplicate id will definitely conflict.Use unique ids where ever possible.
0

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");
            }
            }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.