Popup Window Problem
Hi Folks
I'm having problems with bringing up the popups.
I have the Gender popup and the Form Incomplete popup working. Except the Education popup. What am I doing wrong?
See the code below. If you can help me, that would be muchly appreciated.
<html>
<head>
<title>Form Validation</title>
<script type="text/javascript" language="JavaScript">
<!--
// This function gets the checked Radio Button
function getRadioValue(formname,radioname)
{
var theRadioButtons = document[formname][radioname];
for (i=0;i<theRadioButtons.length;i++)
{
if (theRadioButtons[i].checked)
{
return theRadioButtons[i].value;
}
}
}
// This function checks whether the user has selected both options
// Gender Validation
function validate()
{
var chosenGender = getRadioValue("survey", "gender");
if (chosenGender== null)
{
window.alert("Select Gender");
}
if (chosenGender== "male")
{
document.survey.feedback1.value = "Thank you sir.";
}
if (chosenGender== "female")
{
document.survey.feedback1.value = "Thank you madame.";
}
// End Gender Validation
// Education Validation
var degree = "";
var comments = new Array(5);
comments [0] = 'You are competent.';
comments [1] = 'You are educated.';
comments [2] = 'You are highly educated.';
comments [3] = 'You spent too much time in school';
comments [4] = 'Education details not selected';
for (i=0;i<5;i++)
{
if (degree == "")
{
window.alert("Select Education");
}
if (document.survey['degree'+i].checked)
{
degree = document.survey['degree'+i].value;
document.survey.feedback2.value = comments[i];
}
// End Education Validation
// Check whether the user has entered both Gender & Education fields
if ((chosenGender==null) || (degree == ""))
{
alert("Form incomplete");
return false; // The form will not be submitted for email
}
else
{
alert("Thank you");
return true; // The form will be submitted via an email
}
}
//-->
</script>
</head>
<body bgcolor="cyan">
<h2>Visitor Survey Form</h2>
<h4>Please take time to complete the following information</h3>
<form action="mailto:yourname@sbit.qld.edu.au"
method="post" enctype="text/plain" name="survey"
onSubmit="return validate()">
<p>Name:<input type="text" name="visitor"
value="" size="40"></p>
<p>Gender:
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="female">Female</p>
<p>Feedback (Gender):<br>
<input type="text" name="feedback1" value="" size="50"></p>
<h4>Degrees you have earned (check all that apply);</h4>
<p><input type="checkbox" name="degree0" value="H.S.">High School Diploma<br>
<p><input type="checkbox" name="degree1" value="B.A.">Bachelor's Degree<br>
<p><input type="checkbox" name="degree2" value="M.S.">Master's Degree<br>
<p><input type="checkbox" name="degree3" value="Ph.D.">Doctorate<br>
<p>Feedback (Education):<br>
<input type="text" name="feedback2" value="" size="50"></p>
<hr>
<p><input type="submit" value="Send Survey"></p>
</form>
</body>
</html>
# 4 Re: Popup Window Problem
cant be any more specific...can i?
PS. the best way to find out mis-matches is to document the code... in tabbed form.
Hey PallaviDalvi
I managed to find a way to solve it. Tell me if I have done it right.
<html><head>
<title>Radio Button Form Validation</title>
<script type="text/javascript" language="JavaScript">
<!--
// This function gets the checked Radio Button
function getRadioValue(formname,radioname)
{
var theRadioButtons = document[formname][radioname];
for (i=0;i<theRadioButtons.length;i++)
{
if (theRadioButtons[i].checked)
{
return theRadioButtons[i].value;
} // end if
} // end for
} // end function
// This function checks whether the user has selected both options
function validate()
{
// Gender Validation
var chosenGender = getRadioValue("survey","gender");
if (chosenGender==null)
{
document.survey.feedback1.value = "Please specify the gender";
}
if (chosenGender== "male")
{
document.survey.feedback1.value = "Thank you sir.";
}
if (chosenGender== "female")
{
document.survey.feedback1.value = "Thank you madame.";
}
// End Gender Validation
// Education Validation
var degree ="";
var comments = new Array(5);
comments [0] = 'You are competent.';
comments [1] = 'You are educated.';
comments [2] = 'You are highly educated.';
comments [3] = 'You spent too much time in school';
comments [4] = 'Education details not selected';
for (i=0;i<4;i++)
{
if (document.survey['degree'+i].checked)
{
degree = document.survey['degree'+i].value;
document.survey.feedback2.value = comments[i];
} // end if
} // end for
if (degree == "")
{
document.survey.feedback2.value = comments[4];
}
// End Education Validation
// Check whether the user has entered both Gender & Education fields
if ((chosenGender==null) || (degree == ""))
{
if (chosenGender==null)
{
alert("Select Gender");
}
if (degree == "")
{
alert("Select Education Level");
}
alert("Form Incomplete");
return false; // The form will not be submitted for email
}
else
{
return true; // The form will be submitted via an email
}
}
//-->
</script>
</head>
<body bgcolor="cyan">
<h2>Visitor Survey Form</h2>
<h4>Please take time to complete the following information</h3>
<form action="mailto:teknoman04@bigpond.com"
method="POST" enctype="text/plain" name="survey"
onsubmit="return validate();">
<p>Name:<input type="text" name="visitor"
value="" size="40"></p>
<p>Gender:
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="female">Female</p>
<p>Feedback (Gender):<br>
<input type="text" name="feedback1" value="" size="50"></p>
<h4>Degrees you have earned (check all that apply);</h4>
<p><input type="checkbox" name="degree0" value="H.S.">High School Diploma<br>
<p><input type="checkbox" name="degree1" value="B.A.">Bachelor's Degree<br>
<p><input type="checkbox" name="degree2" value="M.S.">Master's Degree<br>
<p><input type="checkbox" name="degree3" value="Ph.D.">Doctorate<br>
<p>Feedback (Education):<br>
<input type="text" name="feedback2" value="" size="50"></p>
<hr>
<p><input type="submit" value="Send Survey"></p>
</form>
</body>
</html>