<![CDATA[ Associated Array & Ajax Help needed - My Forums]]> https://forums.modx.com/thread/?thread=104014 <![CDATA[Associated Array & Ajax Help needed]]> https://forums.modx.com/thread/104014/associated-array-ajax-help-needed#dis-post-559362 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]]]>
forbesn Jul 05, 2018, 10:38 PM https://forums.modx.com/thread/104014/associated-array-ajax-help-needed#dis-post-559362
<![CDATA[Re: Associated Array & Ajax Help needed]]> https://forums.modx.com/thread/104014/associated-array-ajax-help-needed#dis-post-560499
Seems like there should have been a data driven way to do this but fortunately, this data doesn't change often. I'll periodically have to replace the county dropdown chunks when salesmen change.]]>
forbesn Aug 07, 2018, 09:34 PM https://forums.modx.com/thread/104014/associated-array-ajax-help-needed#dis-post-560499