Hello I am new to Javascript and currently trying to update another developers code. I have a very simple 4 question for with a mix of checkboxes and text fields.
My first piece of Javascript works: it says if there is no info typed in postsitesurvey then alert that it must be filled out. The next step I am stuck on. The employee has 2 visible options and 1 hidden. Were parts left over? I want it that if he checks yes then the next field which is the Left with field must be filled out and if not yes then he can go ahead and submit the form. Any help would be appreciated.
echo "<form id=\"myForm\" name=\"myForm\" method=\"post\" action=\"edit.php?
action=upbill2\" onsubmit=\"return validateForm()\">";
echo "<table width=\"100%\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\"
class=\"table2\">";
echo "<div class=\"col-sm-6\">";
echo "<b>Post Site Survey</b>";
Echo "   ";
echo "<textarea style=\"width:70%\" name=\"postsitesurvey\"
id=\"postsitesurvey\" value=\"$postsitesurvey\" />";
echo $postsitesurvey;
echo "</textarea>";
echo "</div>";
echo "<div class=\"col-sm-6\">";
echo "<b>Was There Equipment Left Over?</b>";
Echo "   ";
echo "<input name=\"eq_left\" type=\"checkbox\" id=\"eq_left_yes\"
value=\"1\"";
if ($eq_left == "1") { echo " checked=\"checked\" "; }
echo "/>    Yes ";
Echo "   ";
echo "<input name=\"eq_left\" type=\"checkbox\" id=\"eq_left_no\"
value=\"2\"";
if ($eq_left == "2") { echo " checked=\"checked\" "; }
echo "/>    No ";
echo "</div>";
echo "<input name=\"eq_left\" type=\"checkbox\" id=\"eq_left_empty\"
value=\"\" style=\"display:none;\" checked";
if ($eq_left == "") { echo " checked=\"checked\" "; }
echo "</div>";
echo "<div class=\"col-sm-6\">";
echo "<b>Left with?</b>";
Echo "   ";
echo "<input style=\"width:45%\" name=\"eq_poc_\" type=\"text\"
id=\"eq_poc\" value=\"$eq_poc\" placeholder=\"Name of customer\"";
echo "</div>";
echo "    or";
Echo "   ";
echo "<input name=\"eq_poc\" type=\"checkbox\" id=\"chkNo\" value=\"MCS\"";
if ($eq_poc == "MCS") { echo " checked=\"checked\" "; }
echo "/>    MCS";
echo "</div>";
echo "<br>";
echo "<div class=\"col-sm-12 text-center\">";
echo "<input name=\"st_id\" type=\"hidden\" id=\"st_id\" value=\"3\" />";
echo "<input name=\"job_id\" type=\"hidden\" id=\"job_id\" value=\"$job_id\" />";
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\" class=\"btn btn-primary\"/>";
echo "</div>";
echo "</table>";
echo "</form>";
}
----JAVASCRIPT----
function validateForm() {
var x = document.forms["myForm"]["postsitesurvey"].value;
if (x == "") {
alert("Post site survey must be filled out");
return false;
}
echostatements in your code, especially with having to backslash all your quotes, is making your life way more difficult than it has to be.<?phptag it's just text that gets displayed. A file withtestin it will echo just that when run withphp test.php<?phpand?>tags is not considered PHP. Anything inside of those tags is considered PHP code and is not echoed by default.