jQuery - Show field based on value of a type-hidden on refresh.

Posted by Sebhael on Stack Overflow See other posts from Stack Overflow or by Sebhael
Published on 2010-12-25T03:34:14Z Indexed on 2010/12/25 3:54 UTC
Read the original article Hit count: 224

Filed under:

Hello, I'm trying to create something in jQuery and having a bit of problems with it. I'm not too adept on the framework, so I'm sure this is all wrong.

Anyways, the ultimate goal is a full form that contains 3 radio buttons - depending on the value of the button, a LI is shown. I have all of that done, but my problem is coming with validation. If something fails then the page is reloaded and the div that was selected doesn't show without clicking another radio first, then back to the original. This process is basically the same as someone came up with here.

Here's what I got so far.

HTML

 <li> <label> License (radio) </label>
 <label for="commercial" class="checkBox"> Commercial </label> 
     <input type="radio" name="license" value="commercial" id="commercial" class="checkBox" <?php echo set_radio('license', 'commercial'); ?> />
    <label for="abandonware" class="checkBox"> Abandonware </label>
        <input type="radio" name="license" value="abandonware" id="abandonware" class="checkBox" <?php echo set_radio('license', 'abandonware'); ?> />
    <label for="freeware" class="checkBox"> Freeware </label>
        <input type="radio" name="license" value="freeware" id="freeware" class="checkBox" <?php echo set_radio('license', 'freeware'); ?> />
   </li>

This is followed by three LI's that contain id="commercial, abandonware, and freeware" and class="licenseli"

My jQuery is, as said, something from here.

 $('li.licenseli').hide();
    $('input[name=license]:radio').change(function(){
    var Type = $(this).val(); // Get value of radio
    $('li.licenseli').slideUp(); // Hide non-selected
    $('li#'+Type).slideDown(); // Show Selected
});

So what I need help with is I have a hidden input that retrieves the value of the radio box from validation - I want to take this value (or the radio's if possible?) and have the original selected option's LI already visible.

© Stack Overflow or respective owner

Related posts about jQuery