I see the problem. This line:
if ( $(this).attr("checked", true) )
Should be:
if( $(this).attr("checked") )
or, similarly
if( $(this).is(":checked") )
What you are doing with your current code is actually setting the radio to
checked=true -- when the "attr" method has two arguments, the first argument
is set to the value of the second. When the "attr" method has one argument,
it returns the value of the argument.
- Josh
----- Original Message -----
From: "choffman" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Thursday, November 01, 2007 12:52 PM
Subject: [jQuery] Re: Form function no firing
Hi Josh,
Thanks for getting back to me. I'm not going to be using the Validate
plug-in. I think this can be done with jquery alone. It doesn't seem
all that complex. The main issue at the moment is getting the event-
handler to run the function (checkRadio) when the submit button is
pressed. I changed the script a little bit since the original post.
I'm open to any advisement and code snippets. Mentioned earlier, I
started using jquery a few weeks ago so please bear with me. The main
goal of the script is make the <h3 id=billing> tag red if they skip
the radio buttons. Thanks - CH
$("#register").submit( function() {
checkRadio();
});
function checkRadio () {
$('input.amount').each(function() {
if ($(this).attr("checked", true)) {
return true;
} else {
$("#billing").css('color', '#C60006').show();
return false;
}
//close function
}
On Nov 1, 12:57 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
It doesn't look like you are using the Validate plugin in the way it's
intended. You might want to have a look at the plugin's home page for
more
information on its usage.
Your submit function should look something like:
$("#register").submit(function() {
$(this).validate(options);
});
...where options contains the Validation configuration object, which is
where validation rules, messages, and error placements are set up.
-- Josh
----- Original Message -----
From: "choffman" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Thursday, November 01, 2007 9:58 AM
Subject: [jQuery] Form function no firing
> Hi There,
> I could use some jquery help here. Its probably something very simple
> that I'm missing. I started using jquery a few weeks ago so please
> bear with me.
> In a nut shell, when a user submits the form (form id="register"), I
> want it check to make sure they have selected a radio button
> (class="amount"). If they forgot, I want it turn the #billing id (<h2
> id="billing>) red. I have server side validation working using PHP.
> This is more of a visual indicator. I'm using the validate.js plug-in
> and jquery 1.2.1. Any help would be great!
> $(document).ready(function() {
> $("#register").submit( function() {
> checkRadio();
> });
> function checkRadio() {
> $('input.amount').each(function() {
> if ($('input:unchecked')) {
> $("#billing").css('color', '#658300').show();
> return true;
> } else {
> $("#billing").css('color', '#C60006').show();
> return false;
> }
> });
> //close function
> };
> });