The following echo statement creates an empty textbox and a submit button using php.
echo"<td><form id=\"edit\" name=\"edit\" method=\"post\" action=\"../assets/modules/coursemanager/process.cm.php\" onsubmit=\"return check_edit();\">
<input type=\"text\" size=\"3\" id=\"edit_places\" name=\"edit_places\" value=\"\" />
<input type=\"hidden\" name=\"sid\" value=\"".$sid."\" />
<input type=\"submit\" name=\"Submit\" value=\"edit places\" /></form></td>";
This is the validation JavaScript I am using, but the above form is ignoring it.
function check_edit(){
var notempty=document.forms["edit"]["edit_places"].value;
if(notempty==null || notempty==""){
alert("Please enter the new number of available places and try again");
return false;
}else{
return true;
}
}
I would be very grateful if someone could show me my error.
notempty==nul || notempty==""should benotempty==null || notempty=="". Also because of how Javascript works, a simpler way of saying that isif(!notempty), which will handlenulland""but alsoundefinedfalseand0. If you only want to checknull/"", you should use===instead of just==.nullis misspelled on the third line