Ajax Dropdown

someguy2k 28 Jun, 2011
I read through Greyheads Ajax double drop-down tutorials and haven't been able to get my Javascript to respond to domEvents. I used the methods in Greyheads - double drop-down with Ajax tutorial for my form with no luck.

Form HTML:
<div class="form_item">
  <div class="form_element cf_text"> <span class="cf_text">Request Record</span> </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Week Ending</label>
    <select class="cf_inputbox" id="myweek" size="1" title=""  name="myweek">
		<option value="">==??==</option>
		<?php 
		    $db =& JFactory::getDBO();
			$query = "Select DISTINCT `weekending` FROM #__chronoforms_corpreporting;";
			$db->setQuery($query);
			$count = $db->loadAssocList();
			$i = 1;
			$thiWeekending = $count[$i]['weekending'];  
			while ($thisWeekending != "" or $thisWeekending != null ) { $thisWeekending = $count[$i]['weekending']; echo "<option value='".$thisWeekending."'>" . $thisWeekending . "</option>";	$i++; }	
		?>
    </select>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
	<div class="form_element cf_dropdown">
		<label class="cf_label" style="width: 150px;">Store Name </label>
		<span id='ajax_getuser' style='color:#444;'>Select Store Name</span>    
		<span id='progress_getuser' style='visibility:hidden;'>Searching...</span>    
	</div>
	<div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="next" name="next" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>

I am able to populate the 1st drop down but nothing happens when I select a value.
Form Javascript:
window.addEvent('domready', function()
{
	$('myweek').addEvent('change', function() {
		var a = $('myweek').value;
		if ( a != null && a != '' ) {
			getUser(a);
		} else {
			$('ajax_getuser').setHTML("<span id='ajax_getuser' > No Record Found</span>")
		}
	});
});

function getUser(a){
	var url="index.php?option=com_chronocontact&chronoformname=requestInfo&task=extra&format=raw";
	new Ajax(url, {
		method: 'get', 
		onRequest: functoin(){
			$('progress_getuser').setStyle('visibility', 'visible');
		}, 
		onComplete: function(){
			$('progress_getuser').setStyle('visibility', 'hidden');
		},
	update: $('ajax_getuser'),
	data: 'we='+a
	}).request();
};


Form Extra Code:
<?php 
 $week =& JRequest::getString('we', '', 'get);
 if ($week) 
 {
	$db =& JFactory::getDBO();
	$query = "Select DISTINCT `user` AS `id`, `user` FROM #__chronoforms_corpreporting WHERE `weekending` = '$week';";
	$db->setQuery($query);
	$data = $db->loadAssocList();
	if ( count($data) ) {
		$m = new stdClass();
		$m->id = 0;
		$m$->user = '==?==';
		$data = array_merge(array($m), $data);
		$return = JHTML::_('select.genericlist', $data, 'user', 'class="inputbox required select" size="1" ', 'id', 'user', 0);
	} else {
		$return = "Sorry, user record not found";
	}
	
	} else {
		$return = "Sorry, unknown error";
	}
	
	echo $return;
	?>


I can't see the problem, any help is appreciated.
GreyHead 29 Jun, 2011
Hi someguy2k,

Do you get any JavaScript errors on the page?

Please post a link to the form so we can take a quick look.

Bob
someguy2k 29 Jun, 2011
Thanks for pointing out the typo Bob, I'm now calling the function and made sure to add jQuery.noConflict(); to my JS box and now get the following.

Parse error: syntax error, unexpected T_VARIABLE in /home/nuemind/public_html/cheeburgercorp.com/corpreporting/components/com_chronocontact/libraries/chronoform.php(516) : eval()'d code on line 6


extradeCode: Line #6
$query = "Select DISTINCT `user` AS `id`, `user` FROM #__chronoforms_corpreporting WHERE `weekending` = '$week';";

-joel
someguy2k 29 Jun, 2011
I found the 2nd typo in the extracode, it was in the 1st line. Thanks for your help Bob.
This topic is locked and no more replies can be posted.