Hi, guys. How are you?
Well, I am trying to make form for a couple of hours.
What I have done so far is:
code:
<html>
<head>
<title>Selecting one field with another</title>
<script type="text/javascript">
<!--
function submitIt(carForm){
if(carForm.DoorCt[doorOption].value == "fourDoor" && carForm.sunroof.checked){
alert("The sunroof is only available on the two door mode");
return false;
}
return true;
}
function doorSet(sunroofFiled){
if(sunroofField.checked){
for(i=0; i<document.myForm.DoorCt.length; i++){
if(document.myForm.DoorCt[i].value == "twoDoor"){
document.myForm.DoorCt[i].checked = true;
}
}
}
}
-->
</script>
</head>
<body>
<form onSubmit = "return submitIt(this)" name="myForm">
<input type="checkbox" name="sunroof" onClick="doorSet(this)" value="yes"> Sunroof (two door
only)
<input type="checkbox" value="yes"> Power Window
<br />
<input type="radio" name="DoorCt" value="twoDoor"> Two
<input type="radio" name="DoorCt" value="fourDoor"> Four
<br />
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
But some reason doesn't work.
What I'd like to do is that if user choose sunroof with Four, alert pops up to prevent user doing so. User only can submit sunroof with Two. Here is my uploaded file.
Many thanks.
Hiroki Kozai