tonelm54
asked on
Test form values before submit
Ive been playing about trying to validate a simple form, and I cannot get it to fail if the Option box still says 'Please Select', or if there are no comments.
My code Im running to test is:-
And the Form is quite simple:-
I just dont understand, why it keeps submitting fine, where if the option group says 'Please Select' and there is nothing in the comments, then it should fail striaght away.
Any ideas what Im doing wrong?
My code Im running to test is:-
<script type="text/javascript">
function submitForm() {
var $formIssue = false;
if ($("#Category").val == "Please Select")
{
alert("Please select a category");
$formIssue = true;
}
if (($("#Comments").val == "") && ($formIssue == false))
{
alert("Please enter some comment, or descibe the issue");
$formIssue = true;
}
if ($formIssue == false)
{
$("#btnSubmit").attr("disabled", true);
$.post("Help_submit.php", $("#helpRequest").serialize(),
function(data) {
alert(data);
window.location.href = "index.php";
});
}
}
</script>
And the Form is quite simple:-
<form id="helpRequest" action="Help_submit.php" method="post">
<select name="Category">
<option>Please Select</option>
<option>Site Appearance</option>
<option>Login</option>
<option>Certificate Download</option>
<option>Certificate Upload</option>
<option>Missing certificate</option>
<option>Other Issue/suggestion</option>
</select>
<textarea name="Comments" rows="8" cols="45"></textarea>
<input type="button" id="btnSubmit" value="Submit" onclick="submitForm();" />
</form>
I just dont understand, why it keeps submitting fine, where if the option group says 'Please Select' and there is nothing in the comments, then it should fail striaght away.
Any ideas what Im doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<form id="helpRequest" action="Help_submit.php" method="post">
<select id="Category" name="Category" id="Category">
<option>Please Select</option>
<option>Site Appearance</option>
<option>Login</option>
<option>Certificate Download</option>
<option>Certificate Upload</option>
<option>Missing certificate</option>
<option>Other Issue/suggestion</option>
</select>
<textarea name="Comments" rows="8" cols="45"></textarea>
<input type="button" id="btnSubmit" value="Submit" onclick="submitForm();" />
</form>