I have a select box using migxloopcollection to select a name from a custom database table and then trying to use the selected option to query another custom table and report details from the that table.
I am trying to use ajax to pass the selected option to a resource that has no template and has the snippet with a script property.
The select resource has the following code:
<label for="playerId">
Select Member to view:
<span class="error">[[!+fi.error.playerId]]</span>
</label>
<select name="selfullname" id="selfullname">
<option value="0">Select member ...</option>
[[!migxLoopCollection?
&prefix=`agc_`
&usecustomprefix=`agc_`
&packageName=`honours`
&classname=`Playerdetails`
&selectfields=`fullname,id`
&tpl=`tplMemberViewOption`
]]
</select>
<div id="playerhonours"> </div>
<script>
$(document).ready(function(){
$("#selfullname").change(function(){
var selectedoption = $(this).val();
console.log("Player name = " + selectedoption);
if(selectedoption != '0')
{
$.ajax({
type: 'POST',
url: 'getmemberview.html',
data: {memberid:selectedoption},
success: function(data){
$("#playerhonours").html(data);
}
});
}
else
{
$("#playerhonours").html('');
}
});
});
</script>
The getmemberview.html has the following code:
[[!Memberhons? &member=`[memberid]`]]
The snippet code is:
<?php
$path = MODX_CORE_PATH . 'components/honours/';
$result = $modx->addPackage('honours',$path .
'model/','agc_');
if (! $result) {
return 'failed to add package';
} else {
$output = '<p>Mens Captains</p>';
}
/* Get the existing Player */
$memberget = $scriptProperties['member'];
$memberhons = $modx->getCollection('Positionagc',
array('playername'=>$memberget, 'position'=>1));
console.log("Player id = " + $memberget);
/* Show error message if member is not found */
if (empty($memberhons)) {
return ('Could not find member with ID: ' . $memberget);
}
//$members = $modx->getCollection('Playerdetails',array('gender'=>"Male"));
//$output .= '<p>Total: '. count($members) . '</p>';
$output .= '<p>Year Name </p>';
foreach($memberhons as $member) {
$output .= '<p> ' . $member->get('yearwhen');
$output .= ' ' . $member->get('playername') . '<br/></p>';
}
return $output;
However, the selected option is not being passed to the snippet. Is it possible to use Ajax to pass data to a script property or should it be done a different way to use a select box to get details from a custom table?