I am new to js [ Client side scripting ]
I worked on php earlier Now I think i need to use js for my application, here is a tiny code for that .
<form name = "Purchase" action = "purchase.php" method = "POST">
<select name = "pname">
<option value = "p1"> p1 </option>
<option value = "p2"> p2 </option>
<input type = "number" name = "price" required></input>
<input type = "number" name = "Total" required></input>
<input type = "submit" name = "NewPurchase" Value = "Add">
</form>
I would like to validate that all the values are set or not mainly drop down in the form if it is not selected then alert message should display saying that value is not selected I have modified the same file as show below but is not working.
<SCRIPT LANGUAGE="JavaScript">
function validateForm(objForm)
{
var returnStatus = 1;
if (objForm.Make.selectedIndex == 0)
{
alert("Please select a all select options");
returnStatus = 0;
};
if (returnStatus)
{
objForm.submit();
}
}
</script>
modified input submit tag too as
<input type = "submit" name = "NewPurchase" Value = "Add" onClick="validateForm(document.testform)">
Presently I am validating all the values using php in the next page ["purchase.php"] using isset()
Please let me know how to use the same in js .