Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validating radiobuttons

    hi there

    I am validating a form with js. :

    Code:
    <script language="JavaScript">
    function verify( f ) {
      var msg;
      var empty_fields = "";
      
      var k = f.elements['2d_email'];
      if( k.value == "" ) {
        empty_fields += "You did not enter your E-mailadress!\n"
      }
      
      var l = f.elements['2a_volnaam'];
      if( l.value == "" ) {
        empty_fields += "Please fill in your full name!\n"
      }
      
        var m = f.elements['2b_ofnaam'];
      if( m.value == "" ) {
        empty_fields += "Please fill your official name!\n"
      }
      
         var o = f.elements['2d_straat'];
      if( o.value == "" ) {
        empty_fields += "Please fill in a streetname!\n"
      }
        
         var p = f.elements['2d_stad'];
      if( p.value == "" ) {
        empty_fields += "Please fill in a city!\n"
      }
        
         var q = f.elements['2d_land'];
      if( q.value == "" ) {
        empty_fields += "Please fill in a country!\n"
      }
        
         var r = f.elements['2d_postcode'];
      if( r.value == "" ) {
        empty_fields += "Please fill in a postalcode!\n"
      }
        
         var s = f.elements['2d_telefoon'];
      if( s.value == "" ) {
        empty_fields += "Please fill in a telephone number!\n"
      }
      
           var t = f.elements['4a_NFP'];
      if( t.value == "" ) {
        empty_fields += "Please fill if you have had a NFP fellowship\n"
      }
    
             var u = f.elements['4b_NFP'];
      if( u.value == "" ) {
        empty_fields += "Please fill if you have had a NFP fellowship\n"
      }
    
             var v = f.elements['4c_NFP'];
      if( v.value == "" ) {
        empty_fields += "Please fill if you have had a NFP fellowship\n"
      }
      
      if( !empty_fields ) return true;
      
      if( empty_fields ) {
        msg = empty_fields;
      }
      
      alert( msg );
      return false;
    }
    </script>
    however, the radiobuttons

    Code:
    <p><strong>NFP Fellowship<br>
                            <input name="4b_NFP" type="radio" value="yes">
      Yes<br>
      <input name="4b_NFP" type="radio" value="no">
      No </strong></p>
    don't want to be in the error message.

    Code:
          var t = f.elements['4a_NFP'];
      if( t.value == "" ) {
        empty_fields += "Please fill if you have had a NFP fellowship\n"
      }
    
             var u = f.elements['4b_NFP'];
      if( u.value == "" ) {
        empty_fields += "Please fill if you have had a NFP fellowship\n"
      }
    
             var v = f.elements['4c_NFP'];
      if( v.value == "" ) {
        empty_fields += "Please fill if you have had a NFP fellowship\n"
      }
    Why is that? I'm not a scripting guru, i just copy and paste a bit here and there until it works.

    Any ideads?

    tanx
    M@rdi

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function CkForm(f){
    // first charactor of name is best alpha
    if (f.fred.value.length<1&&f['4b_NFP'][1].checked){
     alert('complete textarea');
    }
    
    }
    //-->
    </script></head>
    
    <body>
    <p>
    <strong>NFP Fellowship<br>
    <form >
    <input name="4b_NFP" type="radio" value="yes" checked="checked" >  Yes<br>
    <input name="4b_NFP" type="radio" value="no">  No
    </strong></p>
    <textarea name="fred" rows="5" cols="20"></textarea>
    <input type="button" name="" value="Check Form" onclick="CkForm(this.form);">
    </form>
    </body>
    
    </html>


  •  

    Posting Permissions

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