Is it possible to validate a form so that if a tickbox is ticked, the user must fill in two text fields too.
Basically the form is for inputting potential vacancies to a database and has a section on the job type. this being either full or part time. depending which option they choose they need to fill in two other fields relating to their choice:
Full Time Option
- Weekly Hours
- Salary Per Annum
I'm not trying to be offensive, but that code is Internet Explorer-only. So try this one if you want it to span more web browsers.
Note: Pittimann's suggestion used.
PHP Code:
<html>
<head>
<title>Form Validation</title>
</head>
<script type="text/javascript">
<!--
function validateForm(){
var counter=0;
if(document.theForm.hours.value==""){
counter++}
if(document.theForm.salary.value==""){
counter+=2}
if(counter==1){
alert("Please enter a value for \"Weekly Hours\"");
return false}
else if(counter==2){
alert("Please enter a value for \"Salary Per Hour\"");
return false}
else if(counter==3){
alert("Please enter values for \"Weekly Hours\" and \"Salary Per Hour\"");
return false}
return true}
//-->
</script>
<body>
<form name="theForm" onSubmit="return validateForm()">
Part Time:<input type="radio" name="time" checked> Full Time:<input type="radio" name="time"><br>
Weekly Hours: <input type="text" name="hours"><br>
Salary Per Hour: <input type="text" name="salary"><br>
<input type="submit" value="Submit">
</body>
</html>
Yah, and you might want to rename "Full Time:" to something else because the options "Full Time" and "Part Time" don't really answer the question of "Full Time?" if that made sense. It's hard to convey ideas sometimes. =|
Bookmarks