Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-24-2006, 02:23 PM   PM User | #1
Mardiuzzz
New Coder

 
Join Date: Feb 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Mardiuzzz is an unknown quantity at this point
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
Mardiuzzz is offline   Reply With Quote
Old 01-24-2006, 03:04 PM   PM User | #2
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,382
Thanks: 3
Thanked 466 Times in 453 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
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>
vwphillips is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:25 PM.


Advertisement
Log in to turn off these ads.