Thursday, October 30, 2008

[jQuery] Re: Validating divs depending on show / hide [validate]

whoops, the 3 hiding divs should have been

#co-presenter
#co-presenter2
#co-presenter3

I found this bit of code on Jörn's website

{required: "#co-presenter:visible"}

So, I added it to my script

$(document).ready(function(){
$("#co-presenter").hide();
$("#co-presenter2").hide();
$("#co-presenter3").hide();
$("#presentation-form").validate({
required: "#co-presenter:visible"
});

$("#checkme").click(function(){

if ($("#checkme").is(":checked"))
{
$("#co-presenter").show("slow");
}
else
{
$("#co-presenter").hide("slow");
}
});

$("#checkme2").click(function(){

if ($("#checkme2").is(":checked"))
{
$("#co-presenter2").show("slow");
}
else
{
$("#co-presenter2").hide("slow");
}
});

$("#checkme3").click(function(){

if ($("#checkme3").is(":checked"))
{
$("#co-presenter3").show("slow");
}
else
{
$("#co-presenter3").hide("slow");
}
});

});

For now I'm only trying one of the hidden divs. Unfortunately, it
didn't work. Maybe someone can tell me what I'm doing wrong. Again a
newbie here any help would be appreciated.

On Oct 29, 1:30 pm, C <uncle.chuck...@gmail.com> wrote:
> I'm currently using show/hide in a form, allowing users to add more
> fields to the form.  The problem I'm having is when the divs are
> hidden they are still validated.  How can I prevent the hidden (.hide)
> fields from being validated? You can see the page I'm working on
> here.  http://www.evisions.com/summit/pre-conference/presenter-registration2...
>
> There are 3 divs I'm hiding until checkboxes are selected:
> #co-presenter
> #co-presenter
> #co-presenter3
>
> I don't want these to validate unless they are shown. I'm very new to
> jquery so, any help would be greatly appreciated.

No comments: