Jquery :: Only Validate Textbox If Corresponding Checkbox Checked

Jun 28, 2010

I have a simple form which I am running a validation on a single text box (as shown below, adapted from the milk example).

$(document).ready(function() {
// validate signup form on keyup and submit
var validator = $("#updateModules").validate({
rules: {
guestbookContact: {
required: true,
email: true
},
},
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element) {
if ( element.is(":radio") )
error.appendTo( element.parent().next().next() );
else if ( element.is(":checkbox") )
error.appendTo ( element.next() );
else
error.appendTo( element.parent().next() );
},
// specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function() {
form.submit();
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set   as text for IE
label.html(" ").addClass("checked");
}});

Now I only want to validate the text box if the checkbox "requireEmail" is checked. Is there an easy way to do this?

View 3 Replies


ADVERTISEMENT

JQuery :: Validate Incorrectly Disables Some (not All) Validation If A Checkbox Is Checked?

Jun 14, 2010

I have a fairly straightforward form with validation on a number of fields, all of which is working fine.

I have credit card information fields being validated only if a Payment Method radio button is set to 'Visa' or 'Mastercard', and this is also working correctly.

<input name="payment_method" value="visa" type="radio" class="radio payment_method">Visa
<input name="payment_method" value="mastercard" type="radio" class="radio payment_method">Mastercard

[Code].....

These input names don't appear anywhere else in the HTML document and they're not validated fields, however if either of them are checked, the conditional credit card validation no longer fires, although the remaining non-conditional validation on the page continues to work as normal.

EDIT: It would appear that if *any* of the radio buttons on the form are selected, the payment information validation is disabled.

I'm at a loss as to explain what's happening. I'm leaning towardsinput[#payment_method]:checked syntax, and specifically the :checked syntax as potentially causing the issue

View 1 Replies View Related

Validate When Checkbox Is Not Checked

Aug 20, 2001

I make a checkbox:

<input type="checkbox" name="Agree" value="1">

How can I validate if the checkbox is not checked ? So user have to checked it first if they want to continue.

View 10 Replies View Related

CheckBox - Sum Values To Textbox When Checked

Apr 30, 2010

The problem I have is that the value="" needs to be the ID number of the recordset but still be able to SUM the dollar value on the TEXT box (totalcost) when someone click on each CHECKBOX. The CHECKBOX values will be coming out of a database using PHP. How do I modify the Javascript to accomplish what I'm looking for.

Code:
<script type="text/javascript">
function UpdateCost() {
var sum = 0;
var gn, elem;
for (i=0; i<5; i++) {
gn = 'game'+i;
elem = document.getElementById(gn);
if (elem.checked == true) { sum += Number(elem.value); }
}document.getElementById('totalcost').value = sum.toFixed(2);
}
</script>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<input type="checkbox" id='game0' value="9.99" onclick="UpdateCost()">Game 1 ( 9.99)<br>
<input type="checkbox" id='game1' value="19.99" onclick="UpdateCost()">Game 2 (19.99)<br>
<input type="checkbox" id='game2' value="27.50" onclick="UpdateCost()">Game 3 (27.50)<br>
<input type="checkbox" id='game3' value="45.65" onclick="UpdateCost()">Game 4 (45.65)<br>
<input type="checkbox" id='game4' value="87.20" onclick="UpdateCost()">Game 5 (87.20)<br>
<input type="text" id="totalcost" value="">
</form>

View 14 Replies View Related

Jquery :: Validate Textbox On At Least One Checkbox Selected

May 20, 2009

I have a textbox and 2 checkbox, and I'd like to validate the textbox if at least one of the two checkbox is selected. If is just one checkbox, I'll write:
myTextboxl: {
required: '#myFirstCheckbox:checked'
}
but in the case of 2 checkbox, how can I solve?

View 2 Replies View Related

Show Hide Textbox If Checkbox Checked?

Oct 22, 2011

how do i make it like if the checkbox is checked.. it gets replaced by a textbox like in[url]....i have tried using this:

<script>
function ShowHide(chk,txt)
{ [code].....

View 15 Replies View Related

Show Hide Textbox When Checkbox Is Checked And Unchecked?

May 20, 2009

"show hide textbox when checkbox is checked and unchecked" without using 'window.onload' function

below is the code with window.onload function. if i use this, got some problem. using window.onload function i got this code through coding forums. after that i did some changes according to my requirement.

<html>
<head>
<style type="text/css">
tr {
height: 0.75em;

[Code]....

View 1 Replies View Related

Enable/disable A Textbox On That Row If Checkbox Is Checked/unchecked?

Dec 23, 2010

I have a gridview with a checkbox (CheckBoxActiveClient) in the first column and a textbox (Copies) in the 5th column. I want that row's textbox (Copies ) to be disabled if the checkbox is unchecked in that row.
I wrote a javascript function for this but it doesn't work.

Code:
<script type="text/javascript">
function EnableTextBox()

[code]....

View 8 Replies View Related

Validate Textbox After Checkbox Clicked

Oct 31, 2011

I very new to JavaScript and I need to validate a text field after a checkbox has been clicked. This is part of a larger form validation. I am looking for the simplest and easy solution to this issue. I have seen a couple of other examples that are far too complicated for the my needs. The form is asking a user to identify a referral source. If the referral source is a website, it wants the user to provide a URL. To clarify, all it needs to do is verify that if the website checkbox is clicked then there is text in the corresponding textbox. Here's what i'am been trying to make work

[Code]...

View 5 Replies View Related

Set Color Of Checkbox And Its Text To Green If Checked And Red If It Is Checked?

Mar 26, 2010

I want to set the color of checkbox and its text to green if it is checked and set to red if it is checked.I know how to do that in CSS.

<td><div class='red'><input type="checkbox" name="choice" value="1" checked>Keyboard is Broken</div></td>
<td><div class='red'><input type="checkbox" name="choice" value="2" checked>Ack</div></td>
<td><div class='green'><input type="checkbox" name="choice" value="3" >Ok</div></td>

View 1 Replies View Related

When Checkbox A Is Checked, Automatically Check The Checkbox B?

Jun 21, 2010

So here's what i want to do:

i have 2 checkboxes,

when Checkbox A is checked, i want to automatically check the checkbox B. When A is unchecked, then uncheck B.how can i do that?

View 3 Replies View Related

JQuery :: Checkbox Not Checked After Click?

Oct 4, 2010

I've added some functionality to a checkbox. So that when the checkbox is checked it will display a div, when unchecked it will hide the div. This is working fine except when the checkbox is clicked, it doesn't display the checkmark in it. And when the form is submitted, the checkbox is unchecked.

Checkbox
<input
type
="checkbox"

[Code].....

View 8 Replies View Related

JQuery :: Determine If A Checkbox Is Checked?

Mar 3, 2011

I have the following bit of code:Jquery:

Code:
$("#show_hide:checkbox").click(function(){
if($("#show_hide:checked")){

[code]....

View 2 Replies View Related

JQuery :: Delete Element If Checkbox Checked

Mar 1, 2011

Im trying to delete an element if the checkbox inside it is checked.

if($j(this).find('input[id^="checkbox"]:checked').length == 1)
{
var parts = $j('input[id^="checkbox"]:checked').attr('id').split('-');
$j('input[id^="checkbox"]:checked').each(function(){
$j('dl#row-'+parts[1]).remove();
});
});

however it only removes the last element.

View 6 Replies View Related

JQuery :: Detecting Checked State Of Checkbox?

Sep 8, 2010

This function is getting called as it should. the line "if ($("lumode").attr('checked'))" is not detecting the state of the checkbox properly. It always returns false so mode never gets set to 'all'. (#lumodestate is a button I am using to test the function).

$(function(){
$("#lumode").click(function(){
mode = '';

[code]....

View 1 Replies View Related

JQuery :: Checkbox Perpetually Marked As Checked?

Aug 19, 2009

I'm trying to write an if else statement in javascript so that when acheck box is checked, a table will appear, and when it is checkedagain, another box will appear. However, the checkbox is constantlymarked as checked, and I do not know why. I did not set any checkedattritube to false or true.What gives?

function GetStoryPoints() {
var ownerCheck;
var creatorCheck;

[code]....

View 4 Replies View Related

JQuery :: Open A Hidden Div When Checkbox Is Checked?

Jul 27, 2010

I am trying to open a new window (hidden div) when a checkbox is checked. Right now the way i have it is it is opening when the checkbox is clicked instead of checked.

Here is my code in case someone wants to take a look.

$(document).ready(function() {
$('#imgFiche')
// ($(this).attr('checked')){
.attr('target', '_blank')

[Code].....

View 1 Replies View Related

JQuery :: Show Div Based On Checkbox's Checked?

Oct 4, 2010

I have a list of about 20 check boxes and I want a div to show when 3 have been selected as "Yes" option, how do i go about doing this?

Here is my html code:

<form>
<ul id="quiz-list">
<li>1. My bed partner complains that I snore.
<input id="select1" name="snore" type="radio" value="Yes" class="static_class style1" />Yes

[Code].....

View 5 Replies View Related

JQuery :: Can't Remove Pre-checked Radio/checkbox Attributes

Jun 2, 2010

if you have a form with pre-checked radio or checkbox elements it is not possible to remove the checked states neither with

$('#id').attr('checked', false);
//or
$('#id').attr('checked', '');

nor with
$('#id').removeAttr('checked');

If the elements are not pre-checked but you check them with mouse click - it works as expected. Background: I have a search form which is prefilled based on previous selections and queries but I need a reset button to clear all checkboxes and fields.

View 4 Replies View Related

JQuery :: Checkbox Dynamically Created With Checked Property?

Dec 2, 2010

I am dynamically creating a checkbox element. I need to then have assign the checked property to it or not. But In the code below, it's always checked because the property is present..

Code JavaScript:
$('<input>', {
type: "checkbox",
id: "checkbox" + value.AttributeName,

[Code]....

View 2 Replies View Related

JQuery :: If Checkbox Is Checked Then Display Required Dropdown Field?

Dec 12, 2011

I'm trying to figure out if it makes sense to use jQuery to do the following. I have a form with several checkboxes. If one particular checkbox is checked, I'd like a required dropdown field to appear. Is this something fairly straightforward to do with jQuery?

<script>
<!--
function s(){}
function test(){

[code].....

View 15 Replies View Related

JQuery :: Stop Page Auto-refresh If Checkbox Is Checked?

Jun 20, 2011

Im fairly new to JQuery and need some help. Googling failed me :o have a web page that initially auto refreshes every 30 secs and has a bunch of checkboxes that are initially unchecked. I am trying to make it so that if at least one of those boxes it checked the page stops auto refreshing (without reloading the page, preferably). Is this at all possible? I am using Perl to generate the html.

My auto refresh is in the header, but im open to sticking it somewhere else, as long as it doesnt create crazy memory consumption that i've read about on these forums:<head

[Code]...

View 5 Replies View Related

JQuery :: Clicking Checkbox Doesn't Change Its Checked/unchecked Status?

Apr 2, 2010

I have a set of checkboxes that trigger events on a page. Clicking a checkbox triggers the event correctly and the checked attribute changes in the page source, but in the rendered browser view the checkbox status remains changed. If I load the page with the checkboxes checked, they always remain checked in the browser view. If I load the page with checkboxes unchecked, they always remain unchecked in the browser view.

If I remove the jquery code the checkboxes work as expected, but obviously don't trigger any events. I've tested this in both Safari and Firefox with the same results.

[Code]...

On another note, I'm having problems with the back button when using the forum. If I am looking through a multi-page search and click on a topic and then click the back button, I go to the first page of the search instead of the last page I was looking at. Similarly, when I first previewed this post and clicked "back" I was returned to the topic list instead of the compose-post page.

View 2 Replies View Related

JQuery :: Serializing - Create A Series Of Checkboxes - Only Sees First Checkbox And Indicates Whether It Has Been Checked Or Not

Mar 22, 2011

I have a jQuery form in which I create a series of checkboxes:

<?php

javascript

At the moment createb.php is just testing the form

The Problem is that the serialize function only sees the first checkbox and indicates whether it has been checked or not. It does not see any of the other check boxes. Does anybody have an idea why the other check boxes do not get serialized and what to do about it?

View 3 Replies View Related

JQuery :: Checkbox Checked, True Or False Hide Or Show Other Input And Clear Value?

Jul 28, 2011

Here my script :

<script>
$(document).ready(function(){
$('#test1_invalidation_comment__row').hide();
if($('#test1_invalidation_comment').val())

[Code].....

My script work each two submit can't figure why.

View 1 Replies View Related

Trying To Validate Checkboxes Are Checked?

Sep 15, 2011

I don't understand why my code doesn't work?! I just want to check to see if a checkbox has been checked...

<script language="JAVASCRIPT" type="text/djs">
function checkCheckBoxes() {
if (document.f1.Times[].checked == false
{
alert ('You didn't choose any of the checkboxes!');
return false;

[Code]...

View 19 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved