...

View Full Version : validating radiobuttons



Mardiuzzz
01-24-2006, 03:23 PM
hi there

I am validating a form with js. :


<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


<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.


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

vwphillips
01-24-2006, 04:04 PM
<!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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum