If input type text not null must check radio button

Discussion in 'JavaScript' started by Fracisc, Feb 26, 2009.

  1. #1
    I have a text box where people enter the title of a book.
    If a title is entered the MUST choose if they are the author or not.

    I don`t know how to do the MUST part.

    If the "title" box is empty they have nothing to do with the radio buttons.

    If "title" is there, they must choose if they are "author" or "not author".

    It would be great if we could also show the radio buttons only if a title is entered.
     
    Fracisc, Feb 26, 2009 IP
  2. siothach

    siothach Active Member

    Messages:
    656
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #2
    siothach, Feb 26, 2009 IP
  3. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #3
    I checked that but dunno how to use it....
     
    Fracisc, Feb 26, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Below is a simple example of how this is done, other validation can be done during the server-side processing.

    
         <input type="text" id="txtTitle" onkeyup="textChange();"/><br />
         <table id="buttons" style="visibility: hidden;">
         <tr><td>
         <input type="radio" name="isAuthor" value="is" />Author<br />
         <input type="radio" name="isAuthor" value="isnt" checked  />Not Author<br />
         </td></tr>
         </table>
         <script type="text/javascript" >
            function textChange() {
                if (txtTitle.value == "")
                    buttons.style.visibility = "hidden";
                else 
                    buttons.style.visibility = "visible";
                setTimeout("textChange()",2500);
            }
        </script>
    
    Code (markup):
     
    camjohnson95, Feb 26, 2009 IP