Results 1 to 2 of 2

Thread: Radio button validation using javascript

  1. #1
    Muneeb Guest

    Radio button validation using javascript

    below is the javascript code for radio button validation which is not working properly can some tell me what is the problem !!!

    i get the error of document .form1.group1[i] is not defined
    ----------------------------------------------------------------------------


    <script type="text/javascript">
    function validate()
    {
    if(true)
    {
    var chosen=false;
    var len=document.form1.group1.length;

    var i;
    for(i=0; i<=len; i++)
    {
    document.write(i);
    if(document.form1.group1[i].checked)
    {
    document.write("in if");
    chosen=true;
    }
    }
    if(!chosen)
    {
    alert("select the property type");
    return false;
    }

    }
    else
    {
    alert("in else");
    return false;
    }
    }
    </script>

    <form method="post" name="form1" onsubmit="return validate()">
    <div class="textboxaddproperty">
    <select name="propertytype" id="propertytype">
    <option value="plot">Plot</option>
    <option value="Commercial">Commercial</option>
    <option value="house">House</option>
    </select>
    <input type="radio" value="Sale" name="group1"/>
    Sale
    <input type="radio" value="rent" name="group1"/>
    Rent </div>

    <div style="clear:both"></div>
    <div class=" label"></div>
    <div class="textbox">
    <input type="submit" name="submit" value="Submit" />

    </form>

  2. #2
    Join Date
    Sep 2010
    Location
    India
    Posts
    4
    Try

    if(document.form1.group1[i].checked=='true')

    Hope it will work.

Similar Threads

  1. simple javascript validation for a signup form?
    By c_martini in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 25 Mar 2010, 03:07 PM
  2. Secret Glossy Effect Button Making Secrets Revealed!!!
    By WongFei in forum Graphic Design
    Replies: 1
    Last Post: 27 Sep 2009, 08:06 PM
  3. php radio button form for a poll
    By ketanco in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 27 Sep 2008, 04:03 PM
  4. How to draw flat look on checkbox & radio button ?
    By Setya in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 16 Feb 2006, 03:12 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
  •