Hey guys. I am trying to do something I have never done before.
In PHP I am creating a list of items pulled from a database.
In each row is a textbox and a menu. These are created dynamically based on the number of rows pulled from the database.
My problem is, I need to check the value of each textbox and menu when the form is submitted thru Javascript. Basically, if the menu on row 1 says "Completed" and textbox on row 1 says "0.00" I need to prompt the user.
The way I was trying to do this was to create an array (selStatus[] and txtAmount[]) and then doing a for loop to compare the two. However, I get a Javascript error saying selStatus is not an object when I try to run the Javascript.
I guess the simple question is, can you make an array out of menu and textboxes or is that only for check boxes and radio buttons?
Here is my code
The menu and textbox are named like so
<input name="txtActualAmount[]" type="text" class="textf" id="txtActualAmount[]" value="<?php echo number_format($actualAmount,2,'.',','); ?>">
<select name="selStatus[]">
<option value="Active">Active</option>
<option value="Completed">Completed</option>
<option value="Estimate">Estimate</option>
<option value="Lost">Lost</option>
<option value="<?php echo $jobStatus; ?>" selected><?php echo $jobStatus; ?></option>
</select>
The Javascript is like so
function CheckAmount() {
var form = document.forms[1]
for (var i = 0; i < form.elements.length ; i++) {
if(form.selStatus[i] == "Completed" && form.txtActualAmount[i]=="0.00"){
alert("You have set the status of a job to Completed, but you have not entered an Actual Amount.\n On line"+i);
return false;
}//end if
}//end for
}//end CheckAmount
Thank you! 🙂