Querying the Campaigns:
// Getting the campaigns
$campaigns = $wpdb->get_results(
"SELECT *
FROM tbl_campaigns
ORDER BY campaignID DESC",
OBJECT_K
);
// Displaying the Campaigns
<select name="campaign_list" class="campaign_dropdown">
<?php
foreach($campaigns as $c):
echo '<option value="'.$c->campaignID.'" rel="'.$c->campaignID.'">'.$c->campaign_name.'</option>';
endforeach;
?>
</select>
// JavaScript/jQuery
var $j = jQuery.noConflict();
$j('.campaign_dropdown').change(function(){
if($j(this).val() != '0'){
var rel = $j(this).closest('option').attr('rel');
alert(rel);
}
});
The objective is to display the 'rel' value when selecting an option from the dropdown, however, it consistently returns an undefined message. If this issue is resolved, I intend to use it for loading another page upon selection from the dropdown.
What could be the flaw in the code?