+ Reply to Thread
Results 1 to 4 of 4

Thread: javascript help

  1. #1
    supajason's Avatar
    supajason is offline x10 Lieutenant supajason is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    England........:-)
    Posts
    288

    javascript help

    hello i need some help.

    i have a page like this:

    Code:
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    <form name="requestform" method="post">
    <input type="radio" name="question" value="yes">yes
    <input type="radio" name="question" value="no">no
    <br>
    <input type="radio" name="something" value="yes">yes
    <input type="radio" name="something" value="no">no
    <input type="submit" name="submit" value="submit">
    </form>
    </body>
    </html>
    i have about 20 radio groups (each with 2 buttons) that i need to validate to make sure each of the groups has a radio button checked.

    thank you for your time.
    supajason was here

  2. #2
    t2t2t's Avatar
    t2t2t is offline x10 Elder t2t2t is an unknown quantity at this point
    Join Date
    Sep 2006
    Location
    Europe, Estonia
    Posts
    690

    Re: javascript help

    Code:
    <html>
    <head>
    <title>Test</title>
    <script type="text/javascript">
    <!--
    function radioTest(theForm, amount){
    	j = 0
    	for (i=0;i<theForm.elements.length;i++) {
    		if (theForm.elements[i].type == 'radio' && theForm.elements[i].checked) {
    			j++
    		}
    	}
    	if(j < amount) {
    		alert('Please choose every box!');
    		return false;
    	}
    	return true;
    }
    // -->
    </script>
    </head>
    <body>
    <form name="requestform" method="post" onSubmit="return radioTest(this, 2);">
    <input type="radio" name="question" value="yes">yes
    <input type="radio" name="question" value="no">no
    <br>
    <input type="radio" name="something" value="yes">yes
    <input type="radio" name="something" value="no">no
    <input type="submit" name="submit" value="submit">
    </form>
    </body>
    </html>
    For the 20 radio-group form, change in "radioTest(this, 2)" the number from 2 to 20.

    (I know it's rather cheap way, but it works on every form thrown to it)
    Last edited by t2t2t; 12-30-2008 at 06:56 PM.
    This post has been marked spam 52 times.


  3. #3
    apoorav2 is offline x10Hosting Member apoorav2 is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    13

    Re: javascript help

    You can also use variables.

  4. #4
    kundamor is offline x10Hosting Member kundamor is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    36

    Re: javascript help

    better to create radio buttons group with loose, it will minimize your code.

+ Reply to Thread

Similar Threads

  1. Making a site JavaScript dependent - pros/cons?
    By Tarzan in forum Programming Help
    Replies: 8
    Last Post: 07-11-2008, 10:08 AM
  2. drop down menus with JavaScript disabled?
    By sifaka in forum Free Hosting
    Replies: 1
    Last Post: 05-15-2008, 10:46 AM
  3. javascript and external javascript files problem
    By delon in forum Programming Help
    Replies: 6
    Last Post: 04-27-2008, 12:41 AM
  4. A question about javascript files
    By rlodge in forum Programming Help
    Replies: 6
    Last Post: 12-19-2007, 11:26 AM
  5. XML and Javascript
    By cuteboytm in forum Graphics & Webdesign
    Replies: 1
    Last Post: 09-21-2007, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers