我正在开发一个应用程序,使用php和mysql.I已经为表单验证写了一个javascript代码,但它的工作。使用javascript进行PHP表单验证
function checkForm()
{ if(document.Form1.Gestational_age.value=="")
{
alert('Please select an option for Gestational age in weeks ') ;
return false;
}
else if(document.Form1.PRBC.value=="")
{
alert('Please select an option for PRBC transfusion ');
return false;
}
else if(document.Form1.milk_feeding.value=="")
{
alert('Please select an option for Human milk feeding at both day 7 and day 14 of life');
return false;
}
}
</script>
<title>GutCheckNEC for infants < 1500 grams at birth Gephart,2012</title>
</head>
<body>
<div><b>GutCheckNEC for infants < 1500 grams at birth Gephart, 2012</b></div>
<br>
<form name="Form1" method="post" action ="Form1.php" onSubmit="return checkForm();">
1.   Gestational age in weeks  
<input type="radio" id="Gestational_age" name="Gestational_age" value="0-27"/>0-27
<input type="radio" name="Gestational_age" value="28-31"/>28-31
<input type="radio" name="Gestational_age" value=">32" />32
<br>
2.   PRBC transfusion  
<input type="radio" id="PRBC" name="PRBC" value="Yes"/>Yes
<input type="radio" name="PRBC" value="No"/>No
<br>
3.   Human milk feeding at both day 7 and day 14 of life  
<input type="radio" id="milk_feeding" name="milk_feeding" value="Yes"/>Yes
<input type="radio" name="milk_feeding" value="No"/>No
<br>
<input type="submit" name="submit" value="Next"/>
</form>
</body>
</html>
这是我code.Could的样品请你HEL,为什么我的JavaScript部分没有工作..
什么不起作用?你有任何错误消息? – j0k 2013-03-09 11:10:54
没有错误消息,但它没有验证数据,如果我将这些字段留空,那么它不会给出警报消息。 – user1495220 2013-03-09 11:12:24