dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: 2-part Form Validation

  1. #1
    Join Date
    Aug 2011
    Posts
    37

    2-part Form Validation

    Hello all,

    I have a 2-part form (Part A and Part B).... I would like Part B to be validated ONLY when the visitor selects "Yes" from a couple of radio buttons (Yes or No).
    I have the validation completed for both parts, but I can't figure out how to make Part B validate only when the "Yes" radio button is selected.

    Any help would be much appreciated. Thank you.

    Sergio

  2. #2
    Join Date
    Oct 2013
    Posts
    601
    An extremely basic example of one way to do it.

    HTML Code:
    <!DOCTYPE html>
      <html lang="en">
      <head>
      <meta charset="utf-8">
      <title>validate A - B</title>
      <script>
      onsubmit=function(){
    	validateA();
    	if (document.getElementById('rbY').checked == true){
    		validateB();
    	}
      }
      function validateA(){
    	alert('validateA');
      }
      function validateB(){
    	alert('validateB');
      }	
      </script>
      </head>
      <body>
      <div>
      <form action="#">
      <input type="radio" name="validateB" id="rbY" value="yes">Yes
      <input type="radio" name="validateB" id="rbN" value="no">No<br>
      <input type="submit" value="Submit">
      </form>
      </div>
      </body>
      </html>

  3. #3
    Join Date
    Aug 2011
    Posts
    37
    Thank you so much Kevin2!
    Just one final question... (jQuery is not my forté).

    Aside from the obvious "validateA / validateB and rbY / rbN" are there any place holders in the jquery portion of the code?

    Thank you again,

    Sergio

  4. #4
    Join Date
    Oct 2013
    Posts
    601
    Straight "pure" JavaScript. No JQuery as I know very, very little about it other than to hack a basic script to bend it to my will. The only "placeholder" I know anything about is the HTML5 form attribute: <input type="text" placeholder="Some really cool text">. My ignorance is showing.

    I had kind of hoped you'd know either how to plug in your existing scripts, or to somehow "wrap" them with some version of my code ("bent to your will", obviously ), or to use it as a guide to creating your own JQ function.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles