SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    validate radio button in form

    I am modifying a form and some JavaScript validation code to include validation of a radio button.


    HTML Code:
     <label>Check one:</label>
      <input type=radio name=frequency value="once"> Please send this request only.
      <input type=radio name=frequency value="list"> Please add to your bulk distribution list.


    I have checked Sitepoint JavaScript posts on similar issues, but want to keep the coding style the same as what I am modifying.


    Here is the existing code:


    PHP Code:
      var reWhitespace = /^\s+$/;
     function 
    isEmpty (s) {   
      return ((
    == null) || (s.length == 0) || reWhitespace.test(s));
     }
     
     function 
    ValidateDetails() {
      if (
    isEmpty(document.form1.firstname.value) ||
       
    isEmpty(document.form1.lastname.value) ||
       
    isEmpty(document.form1.address1.value) ||
       
    isEmpty(document.form1.city.value) ||
       
    isEmpty(document.form1.postcode.value) ||
       (
    document.form1.state.selectedIndex == 0)) {
       
    alert("Please provide us with your request details");
       return(
    false);
      } 


    I added after the "postcode" line:

    PHP Code:
       //isEmpty(document.form1.frequency.value) || 

    But that stopped all validation.


    Then I tried below the above script:


    PHP Code:
       if (!document.form1.frequency.checked) {
       
    alert("Please tell us whether this is a one time request or you want to be added to our bulk distribution list.");
       return(
    false); 

    and that stopped all validation, too.


    Any clues?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if (!document.form1.frequency[0].checked && !document.form1.frequency[1].checked) {....
    ::: certified wild guess :::

  3. #3
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Adios. That works great!
    Paul C.
    ClickBasics
    http://www.clickbasics.com


Bookmarks

Posting Permissions

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