I'm working on a small web app that uses drag and drop to add users to projects for management purposes. It's hard to describe the problem without showing the relevant code, so I'll start with that first:

<div id="primary">
			<?php 
			foreach($jobs as $job): 
			?>
				<div id="jobdiv-<?php echo $job->id; ?>">
					<h3><?php echo $job->name; ?></h3>
					<div id="ajaxdiv-<?php echo $job->id; ?>">
						Loading users...
					</div>
				</div>
			<?php
			endforeach;
			?>
		</div>
		<div id="secondary">
			<?php
			foreach($users as $row):
			?>
				<p id="p-<?php echo $row->id; ?>" style="width:0;" class="user" alt="<?php echo $row->id; ?>"><?php echo $row->name; ?></p>
			<?php 
			endforeach; 
			?>
		</div>
<?php 
		foreach($jobs as $job):
		?>
		Droppables.add('jobdiv-<?php echo $job->id; ?>', {
			accept: 'user',
			onDrop: function(element) { 
				$('jobdiv-<?php echo $job->id; ?>').highlight();
				new Ajax.Updater('add_user', '/index.php/user/addUserToJob/' + element.alt + '/<?php echo $job->id; ?>', { method: 'get' });
				new Ajax.Updater('ajaxdiv-<?php echo $job->id; ?>', '/index.php/user/jobDisplay/<?php echo $job->id; ?>', { method: 'get' });
			}
		});
		<?php
		endforeach;
		?>

So the line new Ajax.Updater('add_user', '/index.php/user/addUserToJob/' + element.alt + '/<?php echo $job->id; ?>', { method: 'get' }); works how I'd expect for the most part but element.alt is returned as "undefined." Can anyone see a reason why it would do this? Or maybe a different way? If I wasn't clear enough with my question please ask me to clarify.

Thanks!

Member Avatar for langsor

Scriptaculous -- never use the stuff, I hear it's habit forming and gives you cancer ...

But seriously, I never use code I don't understand, thus code I didn't write myself ... but here's a couple ideas.

Try testing the element object passed into the function to see what data it displays ... maybe this will clear up what's going on.

alert( typeof element );

// or

var txt = '';
for ( i in element ) {
  txt += element + ' :: ' + element[i] + '\n';
}
alert( txt );

If element is an object or function and has an alt property then I have no clue why it's not working. If element has properties but not an alt property defined (populated) then the hangup is on the server end of things, probably in the PHP that the Ajax is talking to.

Good luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.