I'm designing a web form to be used for customers to apply for a service upgrade. I'm currently stuck on an If/Else statement I have to test IF the dropdown is selected on "Ganged Positions*" AND the textbox gangPosition is blank.
This is so that only if they select "Ganged Positions" will the text box beside it need to be validated. IF this condition is true, I then want to validate the textbox to be numeric values only. Here is my code chunk
//GANGED Position
if($meterBase == "Ganged Position*" && $gangPosition == "")
{
$gangPositionError = "Positions Number required";
$error = 1;
}
else if($gangPosition != "" && !is_numeric($gangPosition))
{
$gangPositionError = "Numbers Only";
$error = 1;
}
else
{
$gangPosition = $_POST['GangedPositions'];
$gangPositionError = "";
echo "THIS IS WORKING";
}
Currently the initial double check works, it only spits an error if the "Ganged Positions*" is selected. But it just get's stuck in there and won't get rid of the error even if data is entered. Here is the section of form where it takes place as a potential aid.
<tr>
<td align="right" id="meterbaselabel">Meter Base Location:</td>
<td align="left">
<select class="my_dropdown" name="MeterBaseLocation" id="MeterBaseLocation" style="width: 150px" title="Select the location of the Meter">
<option value="-1" selected>[select--location]</option>
<option <?php if($meterBase=="Existing Outside") echo 'selected="selected"'; ?> value="Existing Outside">Existing Outside</option>
<option <?php if($meterBase=="Inside Moving Out") echo 'selected="selected"'; ?> value="Inside Moving Out">Inside Moving Out</option>
<option <?php if($meterBase=="Relocate") echo 'selected="selected"'; ?> value="Relocate">Relocate</option>
<option <?php if($meterBase=="Ganged Position*") echo 'selected="selected"'; ?> value="Ganged Position*">Ganged Position*</option>
</select>
<td align="left"><input type="text" id="gangedPosition" name="GangedPositions" size="5" title="If meter location requires a Ganged (multiple) position installation, how many positions are needed?"/>*Positions</td>
</td>
</tr>
<tr>
<td></td>
<td><div align="center" class="error"><?php echo $meterBaseError;?></div></td>
<td><div align="center" class="error"><?php echo $gangPositionError;?></div></td>
</tr>