1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to validate any one field in form

Discussion in 'jQuery' started by dineshsingh1984, Dec 4, 2013.

  1. #1
    In my form i want to validate one field mobile or phone which are user want to fill. if user want to fill mobile filed then phone field is not required. and if user want to fill phone field then mobile field is not required.

    my script is..............

    <script type="text/javascript">
    $(function(){
    $("#test_formss").validateset({
    rules: {
    mobiless: { required: true, number: true, minlength:10, maxlength: 10 },
    phoness: { required: true, number: true, minlength:7, maxlength: 15 },
    },
    messages: {
    mobiless: { required: "This Field is Required" },
    phoness: { remote: "This Field is Required" },
    }
    });
    });
    </script>
    <div>
    <form name="test_formss" id="test_formss" action="" method="post" enctype="multipart/form-data" onSubmit="return validateset();">
    <input type="text" name="mobiless" id="" value="">
    <input type="text" name="phoness" id="" value="">
    <input type="submit" name="check_send" id="check_send" value="Submit">
    </form>
    </div>
     
    Solved! View solution.
    dineshsingh1984, Dec 4, 2013 IP
  2. #2
    
    <html>
        <head>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
            <script type="text/javascript">
                $(function(){
                    $('#mobiless, #phonessa').keyup(function() {
                        if($(this).val().length > 0) {
                            switch($(this).attr('id')) {
                                case 'mobiless' : $('#phoness').prop('disabled', true); break;
                                case 'phoness' : $('#mobiless').prop('disabled', true); break;
                            }
                        }else{
                            // reset all
                            $('#mobiless, #phoness').prop('disabled', false);
                        }
                    });
                });
            </script>
        </head>
        <body>
            <div>
                <form name="test_formss" id="test_formss" action="" method="post" enctype="multipart/form-data" onSubmit="return validateset();">
                <input type="text" name="mobiless" id="mobiless" data- value="">
                <input type="text" name="phoness" id="phoness" value="">
                <input type="submit" name="check_send" id="check_send" value="Submit">
                </form>
            </div>
        </body>
    </html>
    
    Code (markup):
     
    HuggyStudios, Dec 6, 2013 IP
  3. dineshsingh1984

    dineshsingh1984 Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    thank for this script............
     
    dineshsingh1984, Dec 6, 2013 IP
  4. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #4
    No problem.
     
    HuggyStudios, Dec 6, 2013 IP