I have a form that has a state and county field, and a hidden field where the destination email address will be submitted (there are many other fields besides these.)
The initial page load should default the state to Nebraska.
The county field should be limited to just counties in the selected state and can default to the 1st one in the list. (Stored procedure will provide the appropriate sort order.)
I made a snippet that contains the following (there will be two columns returned and anywhere from 1-254 records): (
Is this how I would return a recordset inside a PHP array?)
...
$sql = "{call Web_GetCountyData4State(?)}";
$state = $_REQUEST['usState1'];
$params = array(array(&$state, SQLSRV_PARAM_IN));
$stmt = sqlsrv_query($conn, $sql, $params);
if ($stmt === false) {
echo "Error in Code at getCountyData_step1";
die( print_r( sqlsrv_errors(),true));
}
else {
$counties = array();
while ($row = sqlsrv_fetch_array($stmt)) {
$counties[]=$row;
}
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
$countyarray=json_encode($counties);
return $countyarray;
Portions of the HTML/Javascript/jQuery chunk
<select name="usState1" id="stateInput1" class="form-control required" value="[[!+fi.usState1]]" placeholder="State">
[[!getStates]]
</select>
<select name="county1" id="county1" class="form-control required" value="[[!+fi.county1]]" placeholder="county">
<!--Need help with javascript/jquery to populate the drop-down on intial page load (where state="Nebraska")-->
</select>
<input type="hidden" name="ToEmail" value="">
...
$('#stateInput1').change(function(e) {
//
how do I populate the county drop-down?
});
$('#county1').change(function(e) {
//
How do I get the array value for salesman email for the selected county into the hidden ToEmail value?
});[/i]