JQuery validate plugin radio with optional text?

I figured out a solution. Basically, I added/removed a validation rule to the text input based on the radio option that was selected, so that the form could not be submitted if they user selected the "other" radio input. When text was inputted, I updated the "other" radio input's value.

Here's the code: Question? Answer1 answer2 Other (please specify) ...and the jQuery: $("form"). Validate({ errorPlacement: function(error, element) { if (element.

HasClass('optional_input') == false){ error. AppendTo(element. Prev("label")); } else { element.

After(error); } } }); $("div#partner_registration form . Manditory"). Each(function () { $(this).

Rules("add", { required: true }); }); $("input:radio"). Click(function () { var this_name = $(this). Attr("name"); if ($(this).

HasClass('optional_button')){ $("input. Optional_input"). Filter(function() {return $(this).

Attr('id') == this_name; }).focus(); } else { $("input. Optional_input"). Filter(function() {return $(this).

Attr('id') == this_name; }). Val(""). Rules("remove"); } }); $("input.

Optional_input"). Focus(function () { $(this). Rules("add", { required: true }); var this_id = $(this).

Attr("id"); $("input:radio"). Each(function() { if($(this). Attr('name') == this_id && $(this).

HasClass('optional_button') == false) $(this). Attr('checked', false); if($(this). Attr('name') == this_id && $(this).

HasClass('optional_button') == true) $(this). Attr('checked', true); }); }); $("input. Optional_input").

Keyup(function () { var this_name = $(this). Attr("id"); var this_val = $(this).val(); $("input. Optional_button").

Filter(function() {return $(this). Attr('name') == this_name; }). Val(this_val); }); Hope that helps.

Answer 1 answer 2 Other (please specify) The plugin initialization should be something like follows for the above markup. JQuery("#ValidRadio"). Validate({ expression: "if (isChecked('choice_1_1') || isChecked('choice_1_2') || (isChecked('choice_1_2') && jQuery('#text_choice_1_4').val())) return true; else return false;", message: "Please choose or enter an answer" }); You will require jquery.validation.functions.

Js to be included along with jquery.validate.js.

Thanks for the response. Not sure these examples apply. I need to validate one or more radio inputs and a text input as one value.It's the mix of the two types of inputs as one value that I'm finding difficult.

Did I miss something in the examples? – timborden Jun 16 '10 at 16:19 You can instantiate the plugin accordingly. I have edited the answer with an instantiation.

– GeekTantra Jun 17 '10 at 23:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions