javascript validation - if all radio buttons are b

Results 1 to 3 of 3

Thread: javascript validation - if all radio buttons are b

  1. #1
    Join Date
    Dec 1969
    Posts
    702

    Default javascript validation - if all radio buttons are b

    Hi,<BR>I tried the FAQ&#039;s but did not find my specific question. What I have is a form that is dynamically generated depending on how many assignmentws a person has. Let&#039;s say I get 3 choices of assignments back - I then display a radio box beside each choice. I want to make sure the person has made at least one choice before he submits. When I try my javascript I search for chooser.value == null - but of course at least one radio button will be null so I always get the pop up. Can you show me how to loop through the choices?<BR><BR>my code:<BR>function checkinput() {<BR> if (document.selecter.chooser.value == null){<BR> alert ("You need to select at least one choice");<BR> return false;}<BR> return true;<BR>} <BR><BR><BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    8

    Default RE: javascript validation - if all radio buttons a

    John, <BR>Do your radio buttons have the same name, "chooser"? If they do, you should never get null back unless the user never chooses any of them. <BR><BR>You can get past that problem by selecting the first one by default. Put "checked" in the first radio button&#039;s tag. This will make it the selected option when the page is loaded, and you won&#039;t have to check to make sure the user selected an assignment, because the first one will always be selected by default.<BR><BR>Ex:<BR>&lt;input type="radio" name="group1" value="Milk" checked&gt; Milk&lt;br&gt;<BR>&lt;input type="radio" name="group1" value="Butter"&gt; Butter&lt;br&gt;<BR>&lt;input type="radio" name="group1" value="Cheese"&gt; Cheese

  3. #3
    Join Date
    Dec 1969
    Posts
    702

    Default Got answer here...

    Guess I didn&#039;t try hard enough the first time - I applied the code found here and it works perfectly.- Thanks<BR><BR>http://www.aspmessageboard.com/forum/showMessage.asp?F=20&M=180580&P=1

Posting Permissions

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